-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
45 lines (42 loc) · 1.24 KB
/
app.js
File metadata and controls
45 lines (42 loc) · 1.24 KB
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
//Variables
let numeroMaximoPosible = 30;
let numeroSecreto = Math.floor(Math.random() * numeroMaximoPosible) + 1;
let numeroUsuario = 0;
let intentos = 1;
//let palabraVeces = 'vez';
let maximosIntentos = 5;
while (numeroUsuario != numeroSecreto) {
numeroUsuario = parseInt(
prompt(
`Me indicas un número entre 1 y ${numeroMaximoPosible} por favor (tienes ${maximosIntentos} ${
maximosIntentos == 1 ? " intento" : " intentos"
}):`
)
);
console.log(typeof numeroUsuario);
if (numeroUsuario == numeroSecreto) {
//Acertamos, fue verdadera la condición
alert(
`Acertaste, el número es: ${numeroUsuario}. Lo hiciste en ${intentos} ${
intentos == 1 ? "vez" : "veces"
}`
);
} else {
if (numeroUsuario > numeroSecreto) {
alert("El número secreto es menor");
} else {
alert("El número secreto es mayor");
}
//Incrementamos el contador cuando no acierta
//intentos = intentos + 1;
//intentos += 1;
intentos++;
//palabraVeces = 'veces';
if (intentos > maximosIntentos) {
alert(`Llegaste al número máximo de ${maximosIntentos} intentos`);
break;
}
//La condición no se cumplió
//alert('Lo siento, no acertaste el número');
}
}