-
Notifications
You must be signed in to change notification settings - Fork 0
/
arquivo.js
69 lines (48 loc) · 1.73 KB
/
arquivo.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
var erros = []
var sorteado = Math.floor(Math.random()* 100) + 1
const CHANCES = 6
var btreload = document.getElementById('btjogar')
function apostarNumero() {
var inNUmero = document.getElementById('innumero')
var numero = Number(inNUmero.value)
if(numero < 0 || numero > 100 || isNaN(numero) || numero == 0) {
alert('Porfavor digite um numero valido..')
innumero.value = ""
innumero.focus()
return
}
var outErros = document.getElementById('outErros')
var outChances = document.getElementById('outChances')
var outDica = document.getElementById('outDica')
if(numero == sorteado) {
alert('Parabens voce acertou!!!')
btaposta.disable = true
btreload.id = "exibe"
outDica.textContent = ` Parabens!! Número sorteado: ${numero}`
} else if(erros.indexOf(numero) >=0){
alert('Você já apostou o numero:' + numero + ". Tente outro...")
} else {
erros.push(numero)
var numErros = erros.length
var numChances = CHANCES - numErros
outErros.textContent = numErros + "(" + erros.join(',') + ")"
outChances.textContent = numChances
if(numChances == 0) {
alert('Suas chances acabaram...')
btaposta.disable = true
btreload.id = "exibe"
outDica.textContent = "Game over!! Numero sorteado: " + sorteado
} else {
var dica = numero < sorteado ? "Maior" : "Menor";
outDica.textContent = `Dica tente um numero ${dica} Que ${numero}`
}
}
innumero.value = ""
innumero.focus()
}
var btsorteado = document.getElementById('btaposta')
btsorteado.addEventListener('click', apostarNumero)
function jogarDenovo() {
location.reload()
}
btreload.addEventListener('click', jogarDenovo)