let numeroSecreto = 0;
let intentos = 0;
function asignarTextoElemento(elemento, texto){
let elementoHTML = document.querySelector(elemento);
elementoHTML.innerHTML = texto;
return;
}
function verificarIntento(){
let numeroUsuario = parseInt(document.getElementById(`valorUsuario`).value);
if(numeroSecreto === numeroUsuario){
asignarTextoElemento(`p`,`Acertaste el numero en ${intentos} ${(intentos === 1) ? `intento` : `intentos`}`);
document.getElementById(`reiniciar`).removeAttribute(`disabled`);
} else {
//El usuario no acerto
if(numeroUsuario > numeroSecreto){
asignarTextoElemento(`p`,`El numero secreto es menor`);
} else{
asignarTextoElemento(`p`,`El numero secreto es mayor`)
}
intentos++;
limpiarCaja();
}
return;
}
function limpiarCaja() {
let valorCaja = document.querySelector(`#valorUsuario`).value = ``;
}
function generarNumeroSecreto() {
return Math.floor(Math.random()*10)+1;
}
function condicionesIniciales() {
asignarTextoElemento(`h1`,`Juego del numero secreto`)
asignarTextoElemento(`p`,`Indica un numero del 1 al 10`)
numeroSecreto = generarNumeroSecreto;
intentos = 1;
}
function reiniciarCodigo() {
//limpiar input
limpiarCaja();
//indicar mensaje de intervalo de numeros
//generar el numero aleatorio
condicionesIniciales();
//deshabilitar el botón de nuevo juego
document.querySelector('#reiniciar').setAttribute('disable','true')
//inicializar el numero de intentos
}
condicionesIniciales()