Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html>
- <head>
- <title>For loop - Javascript</title>
- <style>
- *
- {
- padding: 0px;
- margin: 0px;
- box-sizing: border-box;
- }
- table
- {
- border-collapse: collapse;
- width: 100%;
- }
- th, td {
- text-align: left;
- padding: 10px;
- }
- tr:nth-child(even){background-color: #f2f2f2}
- th {
- background-color: #CC0000;
- color: white;
- font-size: 1.2rem;
- }
- </style>
- </head>
- <body>
- <script>
- // for(inizializzazione; condizione; incremento)
- // Tabella
- document.writeln("<table>");
- // Intestazione
- document.writeln("<thead>");
- for (i = 0; i <= 10; i++)
- {
- if (i == 0)
- {
- document.writeln("<th style='width: 110px;'>" + "Tabelline" + "</th>");
- }
- else
- {
- document.writeln("<th>" + i + "</th>");
- }
- }
- document.writeln("</thead>");
- // Corpo tabella
- document.writeln("<tbody>");
- for (i = 1; i <= 10; i++)
- {
- document.writeln("<tr>");
- for(j = i; j <= i*10; j += i)
- {
- if (j == i)
- {
- document.write("<th>" + j + "</th>");
- }
- document.writeln("<td>" + j + "</td>");
- }
- document.writeln("</tr>");
- }
- document.writeln("</tbody>");
- document.writeln("</table>");
- </script>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement