alert('Boas-vindas ao jogo do número secreto');
let numeroMaximo = 5000;
let numeroSecreto = parseInt(Math.random() * numeroMaximo + 1);
console.log (numeroSecreto);
let chute;
let tentativas = 1;
// enquanto o chute nao for igual ao numero secreto:
while (chute != numeroSecreto) {
chute = prompt(`Escolha um número entre 1 e ${numeroMaximo}`);
// 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 numero secreto é maior que ${chute}`);
}
//tentativas = tentativas +1;
tentativas ++; //também atribuí mais 1
}
}
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.`);
}
//OU AINDA:
/*
if (tentativas > 1) {
let palavraTentativa = tentativas > 1 ? 'tentativas' : 'tentativa';
alert(`Isso ai! Você descobriu o número secreto ${numeroSecreto} com ${tentativas} ${palavraTentativa}.`);
}
*/