-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
28 lines (23 loc) · 810 Bytes
/
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
let display = document.querySelector('.display');
// console.log(display);
let buttons = [...document.querySelectorAll('.button')];
// let buttons = Array.from(document.querySelectorAll('.button'));
// console.log(buttons);
buttons.map( button => {
button.addEventListener('click', function (event) {
// console.log(event.target.innerText);
switch(event.target.innerText) {
case 'C':
display.innerText = '';
break;
case '←':
display.innerText = display.innerText.slice(0, -1);
break;
case '=':
display.innerText = eval(display.innerText);
break;
default:
display.innerText += event.target.innerText;
};
});
});