Advertisement
fcamuso

Javascript Lezione 28

Mar 22nd, 2022
1,314
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <!DOCTYPE html>
  2. <html lang="it-IT">
  3. <head>
  4.   <meta charset="UTF-8">
  5.   <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.2/dist/css/bootstrap.min.css"
  6.         rel="stylesheet"
  7.   >
  8.   <style>
  9.  
  10.   </style>
  11.   <title>CICLI</title>
  12. </head>
  13. <body>
  14.  
  15.   <script>
  16.     function test()
  17.     {
  18.       //un numero casuale con la virgola tra 0 compreso e 1 escluso
  19.       let estratto = Math.random();
  20.       estratto *= 5; //un numero casuale tra 0 e 4,99999...
  21.       estratto = Math.floor(estratto); //un numero INTERO casuale: 0, 1, 2, 3 o 4
  22.       return estratto;
  23.  
  24.       //variante con UNA sola riga al posto di tutte le precedenti
  25.       //return Math.floor(Math.random()*5);
  26.     }
  27.   </script>
  28.  
  29.   <script>
  30.     let numero_positivo=0;
  31.     //for (;numero_positivo<=0;) numero_positivo = parseInt(prompt("inserire un numero maggiore di 0"));
  32.  
  33.     // do
  34.     // {
  35.     //     numero_positivo = parseInt(prompt("inserire un numero maggiore di 0"));
  36.     //     if (numero_positivo<=0) alert("Solo numeri maggiori di zero");
  37.     // }
  38.     // while (numero_positivo<=0);
  39.  
  40.     let risultato=0;
  41.     // while( (risultato = test() )>0 )
  42.     //   console.log(risultato);
  43.      
  44.     do
  45.     {
  46.       console.log(risultato=test());
  47.     }
  48.     while (risultato>0);
  49.  
  50.     </script>
  51.   </table>
  52.  
  53. </body>
  54. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement