-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
32 lines (31 loc) · 1.19 KB
/
app.js
File metadata and controls
32 lines (31 loc) · 1.19 KB
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
alert("Boas vindas ao jogo do número secreto");
let numeroMaximo = 5000;
let numeroSecreto = parseInt(Math.random() * numeroMaximo + 1);
//Armazena a variavel digitada no prompt
console.log(numeroSecreto);
let chute;
let tentativas = 1;
// enquanto chute não for igual ao n.s.
while (chute != numeroSecreto) {
chute = prompt(`Escolha um número entre 1 e ${numeroMaximo}`);
//Verifica se o chute é igual ao número secreto
// se chute for igual ao número secreto
if (chute == numeroSecreto) {
break;
} else {
if (chute > numeroSecreto) {
alert(`O número secreto é menor que ${chute}`);
} else {
alert(`O número secreto é maior que ${chute}`);
}
//tentativas = tantativas + 1;
tentativas++;
}
}
let palavraTentativas = tentativas > 1 ? "tentativas" : "tentativa";
alert(`Isso ai! Você descobriu o número secreto ${numeroSecreto} com ${tentativas} ${palavraTentativas}.`);
/*if(tentativas >1){
alert(`Isso ai! Você descobriu o número secreto ${numeroSecreto} com ${tentativas} tentativas.`);
}else{
alert(`Isso ai! Você descobriu o número secreto ${numeroSecreto} com ${tentativas} tentativa.`);
}*/