Advertisement
fcamuso

Corso recupero Javascript - video 3

Nov 5th, 2022 (edited)
1,384
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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.   <script>
  12.     // let eta = 0;
  13.     // do {
  14.     //   eta = parseInt(prompt("Dimmi quanti anni hai", 18)); // "18"
  15.            
  16.     //   //eta = parseInt(eta); //conversione esplicita
  17.  
  18.     //   if (eta === 18) {alert("numero!");}
  19.      
  20.     //   if (eta<=0)  
  21.     //     alert("L'eta' deve essere maggiore di zero!");
  22.  
  23.     // } while (eta<=0);
  24.  
  25.     // const num1 = parseInt( prompt("Primo numero") );
  26.     // const num2 = parseInt( prompt("Secondo numero") );
  27.     // const pi_greco = parseFloat( prompt("Dimmi il valore di pi greco"));
  28.    
  29.    
  30.     // B > AZZZZZZZZ
  31.     // "2" > "19999999"
  32.     //if (num1<num2) { alert("primo maggiore del secondo"); }
  33.  
  34.     // let valore = -1;
  35.    
  36.     // do {
  37.      
  38.     //   if (valore!==-1) {
  39.     //     //istruzioni
  40.     //   }
  41.  
  42.     //   //nuovo calcolo/acquisizione di valore
  43.     // } while (valore!== -1);
  44.  
  45.     // while (valore!== -1)
  46.     // {
  47.     //   //istruzioni
  48.  
  49.     //   //nuovo calcolo/acquisizione di valore
  50.     // }
  51.  
  52.     //contare quante lettere a contiene una stringa
  53.     const frase = prompt("Inserisci una frase");
  54.     //alert(frase.length);
  55.  
  56.     //frase = "ciao"  frase[0]==="c"  frase[1]==="i"  
  57.     //frase.length
  58.  
  59.     //let indice = 0;
  60.     let contatore = 0;
  61.     // while (indice<frase.length)
  62.     // {  
  63.      
  64.     //   if (frase[indice]==="a")
  65.     //       contatore = contatore + 1; //contatore += 1; contatore++
  66.  
  67.     //   indice++;
  68.  
  69.     // }
  70.  
  71.     for (let indice=0; indice<frase.length; indice++ )
  72.     {
  73.       if (frase[indice] === "z") break;
  74.  
  75.       if (frase[indice]==="a")
  76.            contatore = contatore + 1; //contatore += 1; contatore+
  77.     }
  78.     alert(contatore);
  79.    
  80.     //calcolare la sommatoria dei primi 100 numeri: 1+2+3+...+100
  81.     let somma=0;
  82.     for (let numero=1; numero<=100; numero++) somma += numero;
  83.     alert(somma);
  84.    
  85.  
  86.  
  87.   </script>
  88. </body>
  89. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement