-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
39 lines (31 loc) · 1.09 KB
/
main.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
//Código feito na imersão
/*var numeroSecreto = parseInt(Math.random() * 1001);
while (chute != numeroSecreto) {
var chute = prompt('Chute um número entre 0 e 1000');
if (chute == numeroSecreto) {
alert('Acertou');
} else if (chute > numeroSecreto) {
alert('Errou... O número secreto é menor');
} else if (chute < numeroSecreto) {
alert('Errou... O número secreto é maior');
}
}
*/
//Desafio da imersão
var numeroSecreto = parseInt(Math.random() * 1000) + 1;
var chute;
var tentativas = 0;
while (chute != numeroSecreto && tentativas < 10) {
tentativas++;
chute = prompt('Chute um número entre 1 e 1000');
if (chute == numeroSecreto) {
alert('Acertou! Em ' + tentativas + ' tentativas.');
} else if (chute > numeroSecreto) {
alert('Errou... O número secreto é menor que ' + chute);
} else if (chute < numeroSecreto) {
alert('Errou... O número secreto é maior que ' + chute);
}
}
if (chute >= 10) {
alert('Você perdeu! O número secreto era ' + numeroSecreto);
}