-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
22 lines (18 loc) · 656 Bytes
/
app.js
File metadata and controls
22 lines (18 loc) · 656 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
const buttons = document.querySelectorAll('button')
const screenDisplay = document.querySelector('.screen')
let calculation = []
let accumulativeCalculation
function calculate(button){
const value = button.textContent
if (value === 'CLEAR'){
calculation = []
screenDisplay.textContent = '.'
} else if (value === '='){
screenDisplay.textContent = eval(accumulativeCalculation)
} else {
calculation.push(value)
accumulativeCalculation = calculation.join('')
screenDisplay.textContent = accumulativeCalculation
}
}
buttons.forEach(button => button.addEventListener('click', () => calculate(button)))