-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
40 lines (33 loc) · 1.04 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
let inp = document.querySelector(".inp");
let nums = document.querySelectorAll(".mainnum")
let value = "";
let data = document.querySelector(".dataValue")
let datastore = "";
data.innerText = "";
let ul = document.querySelector("ul")
nums.forEach(num =>{
num.addEventListener("click",(e)=>{
if(e.target.innerText=="="){
datastore = datastore + value;
value = eval(value);
inp.innerText = value;
}else if(e.target.innerText=="AC"){
addList(datastore,value);
datastore = "";
value="";
inp.innerText = value;
}else if(e.target.innerText=="DEL"){
value = value.slice(0,-1);
inp.innerText = value;
}else{
value += e.target.innerText;
inp.innerText = value;
}
})
})
function addList(datastore,value){
let li = document.createElement("li");
li.classList.add("list")
li.innerText = ` ${datastore} = ${value}`;
ul.appendChild(li);
}