Advertisement
Guest User

multiplication table

a guest
Apr 4th, 2017
370
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.77 KB | None | 0 0
  1. function main(lines) {
  2. let n=Number(lines[0]);
  3. console.log("<table border='1'>");
  4. let firstRow="<tr><th>x</th>";
  5. for (let i = 1; i <= n; i++) {
  6. firstRow+="<th>"+i+"</th>";
  7. }
  8. firstRow+="</tr>";
  9. console.log(firstRow);
  10.  
  11. for (let i = 1; i <= n; i++) {
  12. let nextRow="<tr><th>"+i+"</th>";
  13. for (let k = 1; k <= n; k++) {
  14. nextRow+="<td>"+i*k+"</td>";
  15. }
  16. nextRow+="</tr>";
  17. console.log(nextRow);
  18. }
  19.  
  20. console.log("</table>");
  21. }
  22.  
  23. // main(['5']);
  24.  
  25. <!DOCTYPE html>
  26. <html lang="en">
  27. <head>
  28. <meta charset="UTF-8">
  29. <title>Title</title>
  30. <script src="test.js"></script>
  31. </head>
  32. <body>
  33.  
  34. <script>
  35. document.body.innerHTML=main(['5']);
  36. </script>
  37. </body>
  38. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement