-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
53 lines (44 loc) · 1.56 KB
/
main.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
let displayScreen = document.querySelector(".number ");
let showButtonText = document.querySelectorAll(".show");
// console.log(showButtonText)
// this part shows the items character on the screen
showButtonText.forEach((item) => {
item.addEventListener("click", function showAsText(event) {
const x = event.target.innerText;
if (displayScreen.innerText == 0) {
return (displayScreen.innerText = x);
}
if (displayScreen.innerText.length>=12){
return;
}
return (displayScreen.innerText += x);
//add other buttons that user click on to the number inside the screen
});
});
//equal buttons function
document.querySelector(".equal").addEventListener("click", function isEqualTo() {
// console.log(typeof displayScreen.innerText);
// const y = +(displayScreen.innerHTML); //unary plus doesn't work here
const y = eval(displayScreen.innerText);
console.log(y);
// console.log(typeof y);
displayScreen.innerText = y;
});
//clear all button function
document.querySelector(".clear-all").addEventListener("click", function clearWholeText() {
if ((displayScreen.innerText = !0)) {
displayScreen.innerText = 0;
}
});
//clear button function
document.querySelector(".clear").addEventListener("click", function backspaceButton (){
// if (displayScreen.innerText =! 0) {
let text = displayScreen.innerText ;
if (text.length === 1 ){
displayScreen.innerText = 0;
} else {
displayScreen.innerText = text.substring(0 , text.length-1 )
}
}
// }
)