Adivina en número
JavaScript
Publicado el 18 de Julio del 2021 por Alexander (15 códigos)
13.922 visualizaciones desde el 18 de Julio del 2021
Simple juego de adivina el número:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="css/style.css">
<title>Document</title>
</head>
<body>
<h1>Adivina el número </h1>
<button type="button" id="btn">Empezar a jugar</button>
<script>
const btn = document.querySelector("#btn");
btn.addEventListener("click", () => {
Notification.requestPermission() //Promise
.then(resultado => console.log(resultado))
.catch(error => console.log(error))
let condition = true;
let contador = 0;
let numberRandom = parseInt(Math.random() * 50);
while (condition) {
console.log(numberRandom);
let numberInput = prompt("Input number");
contador++;
if (isNaN(Number(numberInput))) {
console.log("NO es un numero");
}
else {
if (numberInput == numberRandom) {
document.write(`Has acertado|||intentos:${contador}`);
if (confirm("Seguir?")) {
numberRandom = parseInt(Math.random() * 50);
}
else {
condition = false
}
}
else if (numberInput > numberRandom) {
document.write("Has fallado, tu numero es mayor que el numero aleatorio");
}
else {
document.write("Has fallado, tu número es menor");
}
}
}
})
</script>
</body>
</html>
Comentarios sobre la versión: 1.0 (0)
No hay comentarios