-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
34 lines (30 loc) · 1.43 KB
/
script.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
const reset = () => {
document.getElementById("input-box").value = "";
document.getElementById("input-display").value = "";
}
const clearOne = () => {
let inputValue = document.getElementById("input-box").value;
let modifiedInput = inputValue.substring(0, inputValue.length - 1);
document.getElementById("input-box").value = modifiedInput;
}
const displayNum = (num) => {
document.getElementById("input-box").value += num;
let inputNum = document.getElementById("input-box").value;
let lastNum = inputNum[inputNum.length - 1];
let secondLastNum = inputNum[inputNum.length - 2];
// console.log(secondLastNum);
if ((lastNum == '+' || lastNum == '-' || lastNum == '*' || lastNum == '/' || lastNum == '%') &&
(secondLastNum == '+' || secondLastNum == '-' || secondLastNum == '*' || secondLastNum == '/' || secondLastNum == '%')) {
// inputNum = inputNum.replace(secondLastNum, lastNum);
// console.log(inputNum);
inputNum = inputNum.slice(0, inputNum.length - 2) + inputNum.slice(inputNum.length - 1)
// inputNum = inputNum.substring(0, inputNum.length - 1)
document.getElementById("input-box").value = inputNum;
}
}
const displayResult = () => {
let expression = document.getElementById("input-box").value;
let result = eval(expression);
document.getElementById("input-box").value = result;
document.getElementById("input-display").value = expression;
}