let listaDeNumerosSorteados = [];
let numeroSecreto = gerarNumeroAleatorio();
let tentativas = 1;
function exibirTextoNaTela(tag, texto) { let campo = document.querySelector(tag); campo.innerHTML = texto;}
function exibirMensagemInicial() {
exibirTextoNaTela("h1", "Jogo do Número Secreto");
exibirTextoNaTela("p", "Escolha um número entre 1 e 10");
}
exibirMensagemInicial();
function verificarChute() {
let chute = document.querySelector("input").value;
if (chute == numeroSecreto) {
exibirTextoNaTela("h1", "ACERTOU!");
let palavraTentativa = tentativas > 1 ? "TENTATIVAS" : "TENTATIVA";
let mensagemTentativas = VOCÊ DESCOBRIU O NÚMERO SECRETO COM ${tentativas} ${palavraTentativa}
;
exibirTextoNaTela("p", mensagemTentativas);
document.getElementById("reiniciar").removeAttribute("disabled");
} else {
if (chute > numeroSecreto) {
exibirTextoNaTela("p", "O NÚMERO SECRETO É MENOR ");
} else {
exibirTextoNaTela("p", "O NÚMERO SECRETO É MAIOR");
}
tentativas++;
limparCampo();
}
}
function gerarNumeroAleatorio() {
let numeroEscolhido = parseInt(Math.random() * 10 + 1);
if (listaDeNumerosSorteados.includes(numeroEscolhido)) {
return gerarNumeroAleatorio();
}else{
listaDeNumerosSorteados.push(numeroEscolhido); console.log(listaDeNumerosSorteados);
return numeroEscolhido;
}
}
function limparCampo() {
chute = document.querySelector("input");
chute.value = "";
}
function reiniciarJogo() {
numeroSecreto = gerarNumeroAleatorio();
tentativas = 1;
exibirMensagemInicial();
document.getElementById("reiniciar").setAttribute("disabled", true);
}