Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How can I create a Table in JS with "for loops" filled with numbers 1 to 100

I created multiplication table using for loop

now I need to create the same table with numbers 1 to 100 like this one:[table][1]

how do I create this one
[1]: https://i.stack.imgur.com/FAacu.png

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

document.write('<table border="3">');
for (var x = 1; x < 11; x++) {
  document.write("<tr>")
  for (let i = 1; i < 11; i++) {
    document.write("<td>" + x * i + "</td>")
  }
  document.write("</td>")
}
document.write("</table>")

>Solution :

I have looked into your code and seems like logic inside your for loop is not correct.

I am posting a working code logic for this, I hope this is what you need.

document.write('<table border="3">');
for (var x = 1; x <= 100; x += 10) {
  document.write("<tr>");
  for (let i = x; i <= x + 9; i++) {
    document.write("<td>" + i + "</td>");
  }
  document.write("</td>");
}
document.write("</table>");
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading