-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
51 lines (36 loc) · 1.59 KB
/
index.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
let computerNumber
let userNumbers = []
let chances = 0
let maxGuesses = 10
function init() {
computerNumber = Math.floor( Math.random() * 50 + 1)
}
function newGame () {
window.location.reload('newGameButton')
}
function conpareNumbers () {
const userNumber = Number(document.getElementById('inputBox').value) //armazeno o numero da caixa
userNumbers.push(' ' + userNumber) // ele joga para array
document.getElementById('guesses').innerHTML = userNumbers //e depois mostra na tela
if(chances < maxGuesses) {
if (userNumber > computerNumber) {
document.getElementById('textOutput').innerHTML = 'Xíi! Ta Frio! 🥶'
document.getElementById('inputBox')
.value = ''
chances++
document.getElementById('attempts').innerHTML = chances
} else if (userNumber < computerNumber) {
document.getElementById('textOutput').innerHTML = 'Quase! Ta Quente! 🤩'
document.getElementById('inputBox').value=''
chances++
document.getElementById('attempts').innerHTML = chances
} else {
document.getElementById('textOutput').innerHTML = 'ACERTOU!'
chances++
document.getElementById('attempts').innerHTML = chances
}
} else {
document.getElementById('textOutput').innerHTML = `PERDEU!<p>O numero era ${computerNumber}<p> TENTE NOVAMENTE!`
document.getElementById('inputBox').setAttribute('Readonly' , 'Readonly')
}
}