No decorrer da aula os instrutores inserem a função reiniciarJogo(), logo a função fica desse jeito
function reiniciarJogo() { numeroSecreto = gerarNumeroAleatorio(); limparCampo(); tentativas = 1; exibirMensagemInicial(); document.getElementById('reiniciar').setAttribute('disabled',true); }
porém se eu comentar as linhas numeroSecreto = gerarNumeroAleatorio() e tentativas = 1 a função e o programa funcionam normalmente, porque isso acontece? Esses dois pontos não são necessários ?
let numeroSecreto = gerarNumeroAleatorio();
let tentativas = 1;
function exibirTextoNaTela(tag,texto) {
let campo = document.querySelector(tag);
campo.innerHTML = texto;
}
exibirMensagemInicial();
function exibirMensagemInicial() {
exibirTextoNaTela('h1', 'Jogo do número secreto');
exibirTextoNaTela('p', 'Escolha um número entre 1 e 10');
}
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 que o chute');
} else {
exibirTextoNaTela('p','O número secreto é maior que o chute');
}
tentativas++;
limparCampo();
}
}
function gerarNumeroAleatorio() {
return parseInt(Math.random() * 10 + 1);
}
function limparCampo() {
chute = document.querySelector('input');
chute.value = '';
}
function reiniciarJogo() {
//numeroSecreto = gerarNumeroAleatorio();
limparCampo();
//tentativas = 1;
exibirMensagemInicial();
document.getElementById('reiniciar').setAttribute('disabled',true);
}