Advertisement
fcamuso

Corso recupero Javascript - video 5

Nov 7th, 2022 (edited)
1,419
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.29 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4.   <meta charset="UTF-8">
  5.   <meta http-equiv="X-UA-Compatible" content="IE=edge">
  6.   <meta name="viewport" content="width=device-width, initial-scale=1.0">
  7.   <title>Document</title>
  8. </head>
  9. <body>
  10.  
  11.   <button id="btn"> Cliccami e diventero' rosso </button>
  12.    
  13.  <script>
  14.  
  15.    const bottone = document.getElementById("btn");
  16.    bottone.addEventListener("click", function ()
  17.    {
  18.      this.style.color = "white";
  19.      this.style.backgroundColor = "red";
  20.    });
  21.      
  22.    function genera_casuale(lim_inferiore, lim_superiore)
  23.    {
  24.      const estratto = lim_inferiore + Math.floor(Math.random() *
  25.                       (lim_superiore - lim_inferiore + 1));
  26.  
  27.      return estratto; //valore restituito al chiamante
  28.    }
  29.  
  30.    function sommaArray(a)
  31.    {
  32.      let somma = 0;
  33.      for (let i=0; i<a.length; i++) somma += a[i];
  34.      
  35.      return somma;
  36.    }
  37.    
  38.    const somma = function (a)
  39.    {
  40.      let somma = 0;
  41.      for (let i=0; i<a.length; i++) somma += a[i];
  42.      
  43.      return somma;
  44.    }
  45.  
  46.    //let scelta = Math.floor(Math.random()*5); //intero random da 0 a 4
  47.  
  48.    for (let i=0; i<200; i++)
  49.      console.log ( genera_casuale(12, 18) );
  50.  
  51.    console.log(somma([1,1,1,1,1]));
  52.  
  53.  </script>
  54. </body>
  55. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement