-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
36 lines (27 loc) · 848 Bytes
/
app.js
File metadata and controls
36 lines (27 loc) · 848 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
28
29
30
31
32
33
34
35
let buttons = document.querySelectorAll('button');
let screenCalc = document.querySelector('.screen');
let screenText =[];
buttons.forEach( button => button.addEventListener('click', () => buttonAction(button) ));
function buttonAction(button){
const buttonText = button.textContent;
if(buttonText == 'CLEAR'){
screenText = [0];
refreshScreen();
}
else if (buttonText == '=')
{
let result = eval( screenText.join(''));
console.log(result);
screenText.splice(0,screenText.length);
screenText.push(...String(result).split(','));
refreshScreen();
}
else{
screenText.push(buttonText);
refreshScreen();
}
}
function refreshScreen(){
screenCalc.textContent = screenText.join('');
console.log ( screenText.join(''));
}