Advertisement
fcamuso

Javascript Lezione 27

Mar 15th, 2022
1,181
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.     label {font-weight: bold; color: blue;}
  10.     #gamesPosseduti, input+button {width: 50px;}
  11.     table, td {border: 1px solid blue;}
  12.     td {width: 50px; height: 30px;}
  13.   </style>
  14.   <title>CICLI</title>
  15. </head>
  16. <body>
  17.   <div class="container">
  18.     <form id="form">
  19.  
  20.     <button type="button" id="go">GO</button>
  21.     <select id="anno">
  22.  
  23.  
  24.     </select>
  25.    
  26.     </form>
  27.   </div>
  28.  
  29.  
  30.   <script>
  31.     //otteniamo un riferimento al bottone nel DOM
  32.     let rifBottone = document.querySelector("#go");
  33.     rifBottone.addEventListener("click", generaDropDownlist);
  34.  
  35.     function generaDropDownlist()
  36.     {
  37.         let annoPartenza = prompt("Da che anno parto? ");
  38.         let annoArrivo = new Date().getFullYear();
  39.         let elenco = document.querySelector("#anno");
  40.                  
  41.         for (let anno=annoArrivo, progressivo=1 ;anno>=annoPartenza; anno--, progressivo++)
  42.         {
  43.           //<option value="1">2022</option>          
  44.          
  45.           let nuovaOption = document.createElement('option');
  46.           nuovaOption.innerText = anno;
  47.           nuovaOption.value=progressivo;      
  48.          
  49.           if (true)
  50.           {
  51.              if (false)
  52.              {
  53.              
  54.              }
  55.              else
  56.              {
  57.               if (progressivo==7) continue;
  58.  
  59.                if (true)
  60.                {
  61.                 if (progressivo>12) break;
  62.                }
  63.                else
  64.                {
  65.                  
  66.                }
  67.              }
  68.           }
  69.  
  70.           //altre istruzioni
  71.  
  72.           elenco.appendChild(nuovaOption);
  73.  
  74.         }        
  75.     }
  76.   </script>
  77.  
  78.   <table>
  79.     <script>
  80.         //i cicli oltre a poter contenere strutture selettive possono
  81.         //contenere altri cicli (anche di tipi diversi)
  82.         for (let numero_riga=0; numero_riga<10; numero_riga++)
  83.         {
  84.           document.write("<tr>");
  85.          
  86.           for (let numero_colonna=0; numero_colonna<4; numero_colonna++)
  87.             document.write("<td> </td>")
  88.          
  89.           document.write("</tr>");
  90.         }
  91.  
  92.         let numero_positivo=0;
  93.         for (;numero_positivo<=0;) numero_positivo = parseInt(prompt("inserire un numero maggiore di 0"));
  94.         // {
  95.         //   numero_positivo = parseInt(prompt("inserire un numero maggiore di 0"));
  96.         //   // if (numero_positivo<=0)
  97.         //   //  alert("sbagliato, riprova");
  98.         //   // else
  99.         //   //   break;
  100.  
  101.         // }
  102.  
  103.     </script>
  104.   </table>
  105.  
  106. </body>
  107. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement