let numeroSecreto = 0; let numeroIntentos = 0;
console.log(numeroSecreto);
function asignarTextoElemento(elemento, texto) { let titulo = document.querySelector(elemento); titulo.innerHTML = texto; return; }
function verificarIntento(){ let numeroDeUsuario = parseInt(document.getElementById('valorUsuario').value);
console.log (numeroIntentos);
if (numeroDeUsuario === numeroSecreto) {
asignarTextoElemento('p', `Acertaste el numero en ${numeroIntentos} ${(numeroIntentos === 1) ? 'vez' : 'veces' }`);
document.getElementById('reiniciar').removeAttribute('disable')
} else {
if (numeroDeUsuario > numeroSecreto) {
asignarTextoElemento ('p','El numero secreto es menor')
} else {
asignarTextoElemento ('p','El numero secreto es mayor')
}
numeroIntentos++;
limpiarCaja()
}
return;
}
function limpiarCaja() { let valorCaja = document.querySelector('#valorUsuario').value = ''; }
function generarNumeroSecreto() { return Math.floor(Math.random()*10)+1;
}
function condicionesIniciales() { asignarTextoElemento('h1', 'Juego de adivinar el numero'); asignarTextoElemento('p', 'Seleciona un numero numero del 1 al 10'); numeroSecreto = generarNumeroSecreto(); numeroIntentos = 1; }
function reiniciarJuego() { //limpiar caja limpiarCaja(); // indicar mensaje de intervalo de numeros condicionesIniciales(); //generar numero aleatorio //inicializar numero de intentos //deshabilitar boton de nuevo juego document.querySelector ('#reiniciar').setAttribute('disabled','true'); }
condicionesIniciales();