mirror of
https://gitea.smigz.com/smiggiddy/odin-codeprojects.git
synced 2024-12-26 22:30:44 -05:00
feat: works for one operation
This commit is contained in:
parent
67f5d765f5
commit
32524f150e
2 changed files with 26 additions and 7 deletions
|
@ -15,10 +15,10 @@
|
||||||
0
|
0
|
||||||
</div>
|
</div>
|
||||||
<div class="buttons">
|
<div class="buttons">
|
||||||
<button id="clear" class="btn" value="cls" data-clear="">A/C</button>
|
<button id="clear" class="btn" value="cls" data-ops="">A/C</button>
|
||||||
<button id="action" class="btn" value="+/-" data-negate="">+/-</button>
|
<button id="action" class="btn" value="+/-" data-negate="">+/-</button>
|
||||||
<button id="action" class="btn" value="%" data-ops="">%</button>
|
<button id="action" class="btn" value="%" data-ops="">%</button>
|
||||||
<button id="action" class="btn" value="÷" data-ops="">÷</button>
|
<button id="action" class="btn" value="/" data-ops="">÷</button>
|
||||||
<button class="btn" value="7" data-num="">7</button>
|
<button class="btn" value="7" data-num="">7</button>
|
||||||
<button class="btn" value="8" data-num="">8</button>
|
<button class="btn" value="8" data-num="">8</button>
|
||||||
<button class="btn" value="9" data-num="">9</button>
|
<button class="btn" value="9" data-num="">9</button>
|
||||||
|
|
|
@ -18,10 +18,11 @@ const ops = {
|
||||||
this.numFlag = !this.numFlag
|
this.numFlag = !this.numFlag
|
||||||
},
|
},
|
||||||
clear: function(){
|
clear: function(){
|
||||||
this.firstNum = Number();
|
this.firstNum = String();
|
||||||
this.secondNum = Number();
|
this.secondNum = String();
|
||||||
this.operator = undefined;
|
this.operator = undefined;
|
||||||
this.numFlag = false;
|
this.numFlag = false;
|
||||||
|
screen.textContent = "0";
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -47,6 +48,7 @@ function divive(x, y) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function operate(firstNum, secondNum, operator) {
|
function operate(firstNum, secondNum, operator) {
|
||||||
|
console.log(operator);
|
||||||
switch (operator) {
|
switch (operator) {
|
||||||
case '+':
|
case '+':
|
||||||
return add(firstNum, secondNum);
|
return add(firstNum, secondNum);
|
||||||
|
@ -59,6 +61,17 @@ function operate(firstNum, secondNum, operator) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function handleOperation() {
|
||||||
|
first = Number(ops.firstNum);
|
||||||
|
second = Number(ops.secondNum);
|
||||||
|
let result = operate(first, second, ops.operator);
|
||||||
|
updateDisplay(result);
|
||||||
|
ops.operator = undefined;
|
||||||
|
ops.firstNum = result;
|
||||||
|
ops.secondNum = String();
|
||||||
|
ops.numFlag = false;
|
||||||
|
}
|
||||||
|
|
||||||
function updateDisplay(displayValue) {
|
function updateDisplay(displayValue) {
|
||||||
screen.textContent = displayValue;
|
screen.textContent = displayValue;
|
||||||
}
|
}
|
||||||
|
@ -67,12 +80,18 @@ function handleOperatorClick(operatorClicked) {
|
||||||
|
|
||||||
// TODO handle ops for = or clear
|
// TODO handle ops for = or clear
|
||||||
if (operatorClicked === '=' || operatorClicked === 'cls') {
|
if (operatorClicked === '=' || operatorClicked === 'cls') {
|
||||||
console.log('Clear or = pressed');
|
if (operatorClicked === 'cls') {
|
||||||
|
ops.clear();
|
||||||
|
}
|
||||||
|
if (operatorClicked === '=') {
|
||||||
|
handleOperation();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
ops.operator = operatorClicked;
|
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 && ops.numFlag){
|
||||||
console.log(operate(ops.firstNum, ops.secondNum, ops.operator));
|
handleOperation();
|
||||||
|
console.log("this should be second num doing stuff");
|
||||||
} else {
|
} else {
|
||||||
ops.toggleNumFlag();
|
ops.toggleNumFlag();
|
||||||
console.log('set second num');
|
console.log('set second num');
|
||||||
|
|
Loading…
Reference in a new issue