-
Notifications
You must be signed in to change notification settings - Fork 1
/
script.js
30 lines (29 loc) · 920 Bytes
/
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
let string = "";
let button = document.querySelectorAll(".num");
// let star;
// function back() {
// var value = document.getElementById("d").value;
// document.getElementById("d").value = value.substr(0, value.length - 1);
// }
// const back = () => {
// let value = document.getElementById("d");
// };
Array.from(button).forEach((button) => {
button.addEventListener("click", (e) => {
if (e.target.innerHTML == "=") {
string = eval(string.replace("X", "*"));
document.querySelector("input").value = string;
} else if (e.target.innerHTML == "C") {
string = " ";
document.querySelector("input").value = string;
} else if (e.target.innerHTML == "d") {
string = string.slice(0, -1);
// string = "";
document.querySelector("input").value = string;
} else {
console.log(e.target);
string = string + e.target.innerHTML;
document.querySelector("input").value = string;
}
});
});