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

finished functions #72

Open
wants to merge 2 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
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"liveServer.settings.port": 5501
}
75 changes: 54 additions & 21 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,63 @@
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="reset.css">
<link rel="stylesheet" href="style.css">
<!-- <script src="main.js"></script> -->
<title>Document</title>
<script src="main.js"></script>
<title>Calculator</title>
</head>
<body>
<form class="calculator">
<label for="first-number">First Number:</label>
<!-- the "onkeyup" event listener passes its input's "value" to the "saveFirstNumber" function in the main.js file -->
<input type="number" id="first-Number" name="first-Number" placeholder="type the first number" value="" onkeyup="saveFirstNumber(this.value)">
<label for="second-number">Second Number:</label>
<input type="number" id="second-Number" name="second-Number" placeholder="type the second number" onkeyup="saveSecondNumber(this.value)">
<div>
<!-- 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>
<div class="main-container">
<div class="instructions" id="instructions">
<h1> Welcome to the simple calculator!</h1>
<h2>1. Choose your first and second number</h2>
<h2>2. Select the operation</h2>
<h2>3. Click on Equals to get your result!</h2>
<h2>4. Click "Clear" to reset fields</h2>
</div>
<br>
<!-- this "onclick" calls the "equal" function in the main.js file -->
<button type="button" onclick="equals()">Equals</button>
<button type="reset">Clear</button>
</form>
<div id="result"></div>

<form class="calculator">

<div class="number-field">

<div class="first-number-container">
<h3>First Number</h3>
<label for="first-number"></label>
<!-- the "onkeyup" event listener passes its input's "value" to the "saveFirstNumber" function in the main.js file -->
<input type="number" id="first-Number" name="first-Number" placeholder="type the first number" value="" onkeyup="saveFirstNumber(this.value)">
</div>

<div class="second-number-container">
<h3>Second Number</h3>
<label for="second-number"></label>
<input type="number" id="second-Number" name="second-Number" placeholder="type the second number" onkeyup="saveSecondNumber(this.value)">
</div>

</div>

<div class="operation-selection">
<!-- 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" 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 -->
<div class="equals-clear-field">
<button type="button" id="equals-button" onclick="equals()">Equals</button>
<button type="button" id="clear-button" onclick="clearresult()">Clear</button>
</div>

</form>
<div id="result">
<h4>Results:</h4>
<div id="result-field">

</div>
</div>
</div>
</body>
</html>
36 changes: 29 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)
}

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 @@ -51,26 +59,40 @@ const changeOperation = (chosenOperation) => {
// In order to show the user their results we have to access the DOM and stick in the value
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
document.getElementById("result-field").innerHTML = 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 (!firstNum){
firstNum = parseInt(document.getElementById('first-Number').value)
}
if(!secondNum){
secondNum = parseInt(document.getElementById('second-Number').value)
}

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"
default: alert("Choose an operation")
}
}

const clearresult = () => {
document.getElementById('first-Number').value = null
document.getElementById('second-Number').value = null
document.getElementById('result-field').innerHTML = null
}
Binary file added repeating_numbers_background.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
52 changes: 52 additions & 0 deletions reset.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
1. Use a more-intuitive box-sizing model.
*/
*, *::before, *::after {
box-sizing: border-box;
}
/*
2. Remove default margin
*/
* {
margin: 0;
}
/*
3. Allow percentage-based heights in the application
*/
html, body {
height: 100%;
}
/*
Typographic tweaks!
4. Add accessible line-height
5. Improve text rendering
*/
body {
line-height: 1.5;
-webkit-font-smoothing: antialiased;
}
/*
6. Improve media defaults
*/
img, picture, video, canvas, svg {
display: block;
max-width: 100%;
}
/*
7. Remove built-in form typography styles
*/
input, button, textarea, select {
font: inherit;
}
/*
8. Avoid text overflows
*/
p, h1, h2, h3, h4, h5, h6 {
overflow-wrap: break-word;
}
/*
9. Create a root stacking context
*/
#root, #__next {
isolation: isolate;
}
162 changes: 159 additions & 3 deletions style.css
Original file line number Diff line number Diff line change
@@ -1,5 +1,161 @@
body {
margin: 20% auto;
width: 50%;
body{
background-image: url(repeating_numbers_background.jpg);
display: flex;
justify-content: center;
}

.main-container{
margin: 100px 10%;
width: 1200px;
min-width: 1200px;
/* max-width: 1200px; */
height: 75%;
background-color: lightgrey;
opacity: .8;
display: flex;
flex-direction: column;
align-items: center;
}

#instructions{
width:700px;
/* min-width: 500px; */
border: dotted 10px red;
padding: 15px;
}

h1{
font-size: 40px;
text-align: center;
}

h2{
text-align: left;
padding-left: 20%;
}

form{
margin-top: 50px;
border: dashed 3px blue;
width: 700px;
padding-bottom: 30px;
/* height: 400px;
padding: 50px auto auto; */
}

.number-field{
display: flex;
justify-content: space-evenly;
padding: 20px;
}

h3{
text-align: center;
}

.first-number-container{
/* display: flex; */
font-size: 24px;

}

.second-number-container{
font-size: 24px;
}

.operation-selection{
margin-top: 30px;
display: flex;
justify-content: space-evenly;
}

button#addition{
font-size: 24px;
height:50px;
width: 12%;
}

button#subtraction{
font-size: 24px;
height:50px;
/* width: 12%; */
}

button#multiplication{
font-size: 24px;
height:50px;
/* width: 12%; */
}

button#division{
font-size: 24px;
height:50px;
width: 13%;
}

button#modulus{
font-size: 24px;
height:50px;
/* width: 12%; */
}

.equals-clear-field{
margin-top: 20px;
display: flex;
justify-content: space-around;
}

button#equals-button{
font-size: 25px;
height: 70px;
}

button#clear-button{
font-size: 25px;
height: 70px;
}

#result{
margin-top: 50px;
padding-bottom: 100px;
}

h4{
font-size: 30px;
}

#result-field{
border: groove 2px black;
background-color: white;
font-size: 28px;
height: 40px;
width: 200px;
/* padding-bottom: 50px; */
}

@media(max-width: 1200px){

.main-container{
width: 700px;
min-width: 700px;
}

}

@media(max-width: 710px){

.main-container{
width:650px;
min-width:650px;
}

#instructions{
width:650px;
min-width:650px;
}

form{
width:650px;
min-width:650px;
}
}