Advertisement
fbinnzhivko

Untitled

Oct 1st, 2016
511
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function multiplicationTable(input) {
  2.     let size = Number(input[0]);
  3.     let table = "<table border='1'>\n";
  4.     table += "<tr>\n" + "<th>" + "x" + "</th>\n";
  5.     for (let i = 1; i <= size; i++) {
  6.         table += "<th>" + `${i}` + "</th>\n";
  7.     }
  8.     table+="</tr>\n";
  9.     for (let row = 1; row <= size; row++) {
  10.         table += "<tr>";
  11.  
  12.         for (let col = 1; col <= size; col++) {
  13.             if(col==1) {
  14.                 table += "<th>" + `${col * row}` + "</th>\n";
  15.             }
  16.             table += "<td>" + `${col * row}` + "</td>\n";
  17.         }
  18.         table+="<tr>";
  19.     }
  20.  
  21.     table += "</table>";
  22.  
  23.     return table;
  24. }
  25. console.log(multiplicationTable(['3']));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement