Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

initial commit #65

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="style.css">
<!-- <script src="main.js"></script> -->
<!-- <link rel="stylesheet" href="style.css"> -->
<script src="main.js"></script>
<title>Document</title>
</head>
<body>
Expand All @@ -18,9 +18,9 @@
<!-- the "onclick" event listener passes its element's "id" to the "changeOperation" function in the main.js file -->
<button type="button" name="add" id="addition" onclick="changeOperation(this.id)">Add</button>
<button type="button" name="subtract" id="subtraction" onclick="changeOperation(this.id)">Subtract</button>
<button type="button" name="multiply" id="multiplication">Multiply</button>
<button type="button" name="divide" id="division">Divide</button>
<button type="button" name="modulus" id="modulus">Modulus</button>
<button type="button" name="multiply" id="multiplication" onclick="changeOperation(this.id)">Multiply</button>
<button type="button" name="divide" id="division" onclick="changeOperation(this.id)">Divide</button>
<button type="button" name="modulus" id="modulus" onclick="changeOperation(this.id)">Modulus</button>
</div>
<br>
<!-- this "onclick" calls the "equal" function in the main.js file -->
Expand Down
26 changes: 19 additions & 7 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,23 @@ const subtract = (numA, numB) => {
// These variables are already defined but that don't point to functions. It's up to you to build the functions to complete your calculator use:

const multiply = (numA, numB) => {
const product = numA * numB
return product
// * to get a product then return it
// Open up the inspector tool in Chrome and select the Console tab to see what this functions is "logging out" to the console.
console.log(numA, numB)
console.log(chosenOperation)
}

const divide = null
const divide = (numA, numB) => {
const quotient = numA / numB
return quotient
}
// / to get a quotient,

const modulus = null
const modulus = (numA, numB) => {
const remainder = numA % numB
return remainder
}
// and % to get a remainder.

// This function changes the "operation" variable to be equal to the "id" of the button we choose on the web page.
Expand All @@ -52,25 +60,29 @@ const changeOperation = (chosenOperation) => {
const putResultInElement = (operationResults) => {
// access the DOM by writing "document" then use the method "getElementById" and pass it the id, "result".
document.getElementById("result").innerHTML = "Results: " + operationResults
console.log(operationResults)

// Remember, each element has built in properties like "innerHTML" which we can change to anything we like.
// Here we give it a string: "Results: " and add the value of the operation to it.
}

// The function uses the value of "operation" variable to determine which operation function it should use on the number: add, subtract, multiply, divide, or modulus
const equals = () => {
// if (operation === 'addition') {
// putResultInElement(add(firstNum, secondNum))
// } else if (operation ===)
// }
switch (operation) {
case "addition": putResultInElement(add(firstNum, secondNum))
break;
case "subtraction": putResultInElement(subtract(firstNum, secondNum))
break;
case "multiplication": multiply(firstNum, secondNum)
case "multiplication": putResultInElement(multiply(firstNum, secondNum))
break;
case "division": console.log(divide(firstNum, secondNum))
case "division": putResultInElement(divide(firstNum, secondNum))
break;
case "modulus": console.log(modulus(firstNum, secondNum))
case "modulus": putResultInElement(modulus(firstNum, secondNum))
break;
default: "Choose an operation"
}
}

64 changes: 61 additions & 3 deletions style.css
Original file line number Diff line number Diff line change
@@ -1,5 +1,63 @@
body {
margin: 20% auto;
width: 50%;
height: 75%;
width: 100em;
height: 100%;
display: flex;
justify-content: center;
font-family: 'Manrope', sans-serif;
font-family: 'Rowdies', cursive;
font-family: 'Ubuntu', sans-serif;
}
.container {
border: 10px inset rgb(67, 66, 66);
border-radius: 5%;
background-color: green;
padding: 2%;
}
input {
height: 10%;
width: 97%;
}
.calculator-container {
display: flex;
padding-top: 2%;
padding-bottom: 5%;
}
.number-container {
display: flex;
justify-content: space-evenly;
flex-direction: column;
}
.operator-container {
display: flex;
flex-direction: column;
}
.equals {
height: 100%;
width: 40px;
}
button {
color: black;
background-color: rgb(141, 237, 149);
height: 50px;
width: 50px;
font-size: 20px;
font-family: 'Manrope', sans-serif;
font-family: 'Rowdies', cursive;
font-family: 'Ubuntu', sans-serif;
}
.result-container {
background-color: rgb(134, 214, 141);
display: flex;
flex-direction: column;
align-items: center;
border: 2px outset black;
border-radius: 5%;
padding: 3%;
}
.result {
background-color: white;
border: 5px solid black;
border-radius: 5%;
height: 100px;
width: 200px;
}