-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
59 lines (49 loc) · 1.72 KB
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
let numeroSecreto = 0;
let intentos = 0;
console.log(numeroSecreto);
function asignarTextoElemento(elemento, texto) {
let elementoHTML = document.querySelector(elemento);
elementoHTML.innerHTML = texto;
}
function verificarIntento() {
let numeroDeUsuario = parseInt(document.getElementById('valorUsuario').value);
console.log(intentos)
if (numeroDeUsuario === numeroSecreto) {
asignarTextoElemento('p',`Acertaste el Número en ${intentos} ${intentos == 1 ? 'vez' : 'veces'}`);
document.getElementById('reiniciar').removeAttribute('disabled');
//El Usuario no acertó
} else {
if (numeroDeUsuario > numeroSecreto) {
asignarTextoElemento('p','El número secreto es menor');
}else{
asignarTextoElemento('p','El número secreto es mayor');
}
intentos++;
limpiarCaja();
}
return;
}
function limpiarCaja() {
let valorCaja = document.querySelector('#valorUsuario');
valorCaja.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 reiniciarJuego() {
limpiarCaja();
//limpiar la caja
condicionesIniciales()
//Indicar mensaje de intervalo de numeros
//generar el numero aleatorio
//Inicializar el numero de intentos
document.querySelector('#reiniciar').setAttribute('disable','true');
//Desabilitar el boton de nuevo juego
}
condicionesIniciales();