-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
39 lines (35 loc) · 1.11 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
35
36
37
38
39
var stringVal = "";
// display the equation when entered
function disp(value) {
stringVal = document.querySelector("#sum-input-tf").value;
stringVal += value;
document.querySelector("#sum-input-tf").value = stringVal;
}
// calculate when the equal button is pressed
function calculateValue() {
// var sum = document.querySelector("#sum-input-tf").value;
if (stringVal != "") {
var evaluateVal = eval(stringVal);
console.log(evaluateVal);
document.querySelector("#sum-tf").value = evaluateVal;
} else {
document.querySelector("#sum-tf").value = "";
}
}
// remove last character
function remove() {
var strVal = document.querySelector("#sum-input-tf").value;
var newVal = strVal.slice(0, -1);
document.querySelector("#sum-input-tf").value = newVal;
stringVal = newVal;
}
//clear textfields
function clearscreen() {
if (document.querySelector("#sum-tf") != null) {
document.querySelector("#sum-tf").value = "";
}
if (document.querySelector("#sum-input-tf") != null) {
document.querySelector("#sum-input-tf").value = "";
}
stringVal = "";
}