-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
40 lines (30 loc) · 1.08 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
const display = document.querySelector(".display");
const buttonsOperations = document.querySelectorAll(".operation");
const equal = document.querySelector(".equal");
const deleteChar = document.querySelector(".delete");
const clear = document.querySelector(".clear-input");
const plusMinus = document.querySelector(".plus-minus");
const percent = document.querySelector(".percent");
buttonsOperations.forEach(button => {
button.addEventListener("click", event => {
display.value = display.value + event.target.textContent;
})
})
equal.addEventListener("click", event => {
display.value = eval(display.value);
})
clear.addEventListener("click", event => {
display.value = "";
})
deleteChar.addEventListener("click", event => {
display.value = display.value.substring(0, display.value.length-1);
})
plusMinus.addEventListener("click", event => {
if (display.value) {
display.value = eval(display.value);
}
display.value = display.value * (-1);
})
percent.addEventListener("click", event => {
display.value = display.value.replace("%", "/100*");
})