-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
52 lines (43 loc) · 1.3 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
40
41
42
43
44
45
46
47
48
49
50
51
52
var solution = "";
toggler = Array.from(document.querySelectorAll(".btn"));
toggler.forEach(item => {
item.addEventListener("click", (inputvalue) => {
if(inputvalue.target.innerHTML == 'C'){
solution = solution.slice(0, solution.length - 1);
}
else if (inputvalue.target.innerHTML == 'AC'){
solution = "";
}
else if (inputvalue.target.innerHTML == '='){
solution = eval(solution).toString().slice(0,12);
}
else {
solution += inputvalue.target.innerHTML;
solution = solution.slice(0,12)
}
display.value = solution;
});
});
toggler.forEach(press => {
press.addEventListener('keydown', (event) => {
var name = event.key;
if(name !== 1 &&
name !== 2 &&
name !== 3 &&
name !== 4 &&
name !== 5 &&
name !== 6 &&
name !== 7 &&
name !== 8 &&
name !== 9 &&
name !== 0
){
alert("Only Numbers are allowed to be typed");
}
else {
solution += keypress;
}
display.value = solution;
});
});
document.querySelectorAll(".btn").addEventListener