-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.js
46 lines (41 loc) · 1 KB
/
app.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
40
41
42
43
44
45
46
function solveEqn(clicked_id){
let eqn = clicked_id;
let input = document.getElementById("eqn");
if(eqn == "point"){
input.value += "."
}
else if(eqn == "plus"){
input.value += "+"
}
else if(eqn == "sub"){
input.value += "-"
}
else if(eqn == "multiply"){
input.value += "*"
}
else if(eqn == "div"){
input.value += "/"
}
else if(eqn == "modulus"){
input.value += "%"
}
else if(eqn == "equal"){
input.value = eval(input.value)
}
else if(eqn == "reset"){
input.value = null
}
else {
input.value += eqn;
}
}
document.onkeypress = function(e) {
let input = document.getElementById("eqn");
e = e || window.event;
let key = e.keyCode;
let keyName = e.key;
let keyPressed = String.fromCharCode(key);
if(keyName == "Enter" || keyName == "Equal"){
input.value = eval(input.value)
}
}