Advertisement
piffy

3.3.8 Es 6

Aug 29th, 2021
1,038
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 5 0.80 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html lang="it">
  3. <head>
  4.   <meta charset="UTF-8">
  5.   <title>3.3.8 Es 6</title>
  6.    <script>
  7.      let scaduto=false;
  8.      function scadenza() {scaduto=true;}
  9.      setTimeout(scadenza, 30000);
  10.    </script>
  11.  
  12. </head>
  13. <body>
  14.  
  15. <script>
  16.   const numero = Math.floor(Math.random()* 10 + 1);
  17.   let messaggio="";
  18.   let tentativo=1;
  19.   let indovinato=false;
  20.   while (tentativo<6 && !indovinato && !scaduto) {
  21.    let inserito=prompt(messaggio+"Tentativo n."+tentativo+". Che numero ho pensato?");
  22.    if (inserito!=numero)
  23.    { messaggio="Sbagliato!"; tentativo++;}
  24.    else
  25.    {indovinato=true;}
  26.  }
  27.  if (scaduto)   alert("Peccato, tempo scaduto!");
  28.  else {
  29.    if (indovinato) alert("Bravo, hai indovinato!");
  30.    else alert("Peccato, hai perso!");
  31.  }
  32.  
  33. </script>
  34. </body>
  35. </html>
  36.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement