-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
27 lines (24 loc) · 791 Bytes
/
script.js
File metadata and controls
27 lines (24 loc) · 791 Bytes
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
const display=document.querySelector(".display");
const buttons=document.querySelectorAll("button");
const specialChars=["%","+","/","-","+","="];
let output="";
console.log(display)
console.log(buttons)
const calculate = (btnvalue) => {
if (btnvalue === "=" && output !== "") {
output = eval(output.replace("%", "/100"));
} else if (btnvalue === "AC") {
output = ""; // Clear the output
} else if (btnvalue === "DEL") {
output = output.toString().slice(0, -1);
} else {
if (output === "" && specialChars.includes(btnvalue)) return;
output += btnvalue;
}
display.value = output;
console.log(btnvalue);
}
buttons.forEach((button)=>{
button.addEventListener('click',(e)=>
calculate(e.target.dataset.value));
})