mirror of
https://gitea.smigz.com/smiggiddy/odin-codeprojects.git
synced 2024-12-26 22:30:44 -05:00
refactor: split method
This commit is contained in:
parent
c75625be29
commit
67f5d765f5
1 changed files with 17 additions and 12 deletions
|
@ -63,21 +63,26 @@ function updateDisplay(displayValue) {
|
||||||
screen.textContent = displayValue;
|
screen.textContent = displayValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
function calculator(event){
|
function handleOperatorClick(operatorClicked) {
|
||||||
|
|
||||||
if(event.target.dataset.ops === "") {
|
|
||||||
// TODO handle ops for = or clear
|
// TODO handle ops for = or clear
|
||||||
// TODO other ops should indicate a swap to second number
|
if (operatorClicked === '=' || operatorClicked === 'cls') {
|
||||||
ops.operator = event.target.value;
|
console.log('Clear or = pressed');
|
||||||
|
}
|
||||||
|
ops.operator = operatorClicked;
|
||||||
//TODO fix this conditional should be if numFlag and a check if = or additional ops
|
//TODO fix this conditional should be if numFlag and a check if = or additional ops
|
||||||
if(ops.secondNum){
|
if(ops.secondNum){
|
||||||
console.log(operate(ops.firstNum, ops.secondNum, ops.operator));
|
console.log(operate(ops.firstNum, ops.secondNum, ops.operator));
|
||||||
console.log(ops.operator);
|
|
||||||
} else {
|
} else {
|
||||||
ops.toggleNumFlag();
|
ops.toggleNumFlag();
|
||||||
console.log(ops.numFlag);
|
|
||||||
console.log('set second num');
|
console.log('set second num');
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function calculator(event){
|
||||||
|
|
||||||
|
if(event.target.dataset.ops === "") {
|
||||||
|
handleOperatorClick(event.target.value);
|
||||||
}
|
}
|
||||||
else if(event.target.dataset.num === "") {
|
else if(event.target.dataset.num === "") {
|
||||||
if(!ops.numFlag) {
|
if(!ops.numFlag) {
|
||||||
|
|
Loading…
Reference in a new issue