xShub

Untitled

Nov 4th, 2025
769
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. let prodotti = [
  2.     ["ID", "Prodotto", "Prezzo", "Quantità"],
  3.     [1, "Computer", 899.99, 15],
  4.     [2, "Mouse", 25.50, 42],
  5.     [3, "Tastiera", 45.00, 23],
  6.     [4, "Monitor", 299.99, 8],
  7.     [5, "Cuffie", 79.99, 31]
  8. ];
  9.  
  10.  
  11. /*
  12. const int MAX_AGE = 100;
  13. const char GRADE_SCALE = 'A';
  14. const float PI = 3.14159;
  15.  */
  16.  
  17. // Scopo: creare una tabella a partire da array bidimensionale
  18.  
  19. // manca "function" prima del nome della funzione
  20. function generaTabella()
  21. {
  22.     // i nomi delle variabili devono seguire il camelCase
  23.     const tabella = document.createElement("table");
  24.     document.querySelector("body").appendChild(tabella);
  25.  
  26.     let primaRiga = true;
  27.  
  28.     /* funzione intestazione tabella */
  29.     for (let i = 0; i < prodotti.length; i++) {
  30.  
  31.         let elementoIntestazione = prodotti [i];
  32.         let elementoTr = document.createElement("tr");
  33.  
  34.         for (let j = 0; j < elementoIntestazione.length; j++) {
  35.  
  36.             let cella;
  37.  
  38.             if (primaRiga) {
  39.                 cella = document.createElement("th");
  40.             } else {
  41.                 cella = document.createElement("td");
  42.             }
  43.  
  44.             cella.textContent = prodotti[i][j];
  45.             // cella.textContent = elementoIntestazione[j];
  46.             elementoTr.appendChild(cella);
  47.         }
  48.  
  49.         primaRiga = false;
  50.  
  51.         tabella.appendChild(elementoTr);
  52.         // const celle = document.querySelectorAll()
  53.        
  54.     }
  55.     document.getElementById("container").appendChild(tabella);
  56.  
  57. }
  58.  
  59. generaTabella();
  60.  
  61.  
Advertisement
Comments
  • wmgubuw
    2 days
    # text 0.12 KB | 0 0
    1. ⭐Make 3000$ with Swapzone Exchange Method
    2.  
    3. >>> docs.google.com/document/d/1IB4SkLZdU8hex0Kn-GyFHXSSV6kLUXhhOhxPwmEuuc4
Add Comment
Please, Sign In to add comment