-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
53 lines (49 loc) · 1.7 KB
/
index.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
53
let string="";
let buttons=document.querySelectorAll(".button");
let zero=document.querySelector(".zero");
let clickCount=0;
Array.from(buttons).forEach((button)=>{
button.addEventListener("click",(e)=>{
try{
if(e.target.innerText=="="){
string=eval(string);
(document.querySelector(".row .input")).value=string;
}
else if(e.target.innerText=="( )"){
clickCount++;
if (clickCount%2==0){
string=string+")";
}
else{
string=string+"(";
}
(document.querySelector(".row .input")).value=string;
}
else if(e.target.innerText=="C"){
string='';
(document.querySelector(".row .input")).value=string;
}
else if(e.target.innerText=="X"){
string=string+"*";
(document.querySelector(".row .input")).value=string;
}
else{
console.log('Clicked');
string=string+(e.target.innerText);
console.log(string);
(document.querySelector(".row .input")).value=string;
}
}
catch(e){
let inputElement = document.querySelector(".row .input");
inputElement.value = "INVALID";
if (inputElement.value=="INVALID"){// Set the value
inputElement.classList.add("red");
}
}
})
})
zero.addEventListener("click",(e)=>{
string=string+(e.target.innerText);
(document.querySelector(".row .input")).value=string;
})