Quando adicionei a função limpar campo acabou apagando também meu texto 'h1' e 'p' e não consigo achar o erro
Segue o projeto:
let numeroSecreto = gerarNumeroAleatorio (); let tentativas = 1;
function exibirTextoNaTela(tag, texto) { let campo = document.querySelector (tag); campo.innerHTML = texto; }
exibirTextoNaTela('h1', 'Jogo do Numero Secreto!'); exibirTextoNaTela('p', 'Escolha um número de 1 a 100');
function verificarChute () { let chute = document.querySelector ('input').value;
if (chute == numeroSecreto) {
exibirTextoNaTela ('h1', 'Acertou!');
let palavraTentativas = tentativas > 1 ? 'tentativas' : 'tentativa';
let mensagemTentativas = `Você descobriu o número secreto com ${tentativas} ${palavraTentativas}`;
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() { return parseInt(Math.random () *100 +1); }
funcion limparCampo() { let chute = document.querySelector ('input'); chute.value = ''; }