-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
38 lines (30 loc) · 957 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
31
32
33
34
35
36
37
let btnLess = document.querySelector('button#btn-less')
let btnMore = document.querySelector('button#btn-more')
let btnReset = document.querySelector('button#btn-reset')
let display = document.querySelector('p.display')
var count = 0
btnLess.addEventListener('click', diminuiValor)
btnMore.addEventListener('click', aumentaValor)
btnReset.addEventListener('click', resetaValor)
// window.alert(display)
function aumentaValor() {
// window.alert('Entrou aumenta')
count++
display.innerHTML = `<p>${count}</p>`
}
function diminuiValor() {
// window.alert('Entrou diminui')
if (count == 0) {
window.alert('Contador zerado! Operação inválida.')
return
} else {
count--
display.innerHTML = `<p>${count}</p>`
}
}
function resetaValor() {
// window.alert('Entrou reseta')
if (count == 0) { window.alert('Contador já estava Zerado!') }
count = 0
display.innerText = "0"
}