Last active
April 10, 2020 01:47
-
-
Save NickFoden/1380d4f8066c36a46a3f43d1f3c935a7 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var data = { | |
currentValue: 0, | |
operator: "" | |
} | |
const operators = ["+", "-", "x", "/"] | |
keys.forEach(key =>{ // output | |
key.addEventListener('click', () =>{ | |
// if not a number and an operator then we can "save" the display value to our data object and get ready to do some math | |
if(operators.includes(key.value)){ | |
//update our data object current value to be the current display | |
data.currentValue = display.value | |
// then change the display to be the "=" view or other operator etc | |
display.value = key.value; | |
// save the operator to our data objet to get ready to use for some math on the next display value | |
data.operator = key.value | |
} else { | |
// other wise we want to keep adding digits: 6 68 684 | |
display.value = display.value + key.value; | |
} | |
}) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment