Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

77
Views
Question regarding JavaScript multiplication table

I am trying to build a multiplication table and display the results, but need to put the x in the top left corner, for some reason it is showing up on the bottom right, what am I doing wrong?

document.write("<table><tbody>");
var blank = "x";
var cols = 0;
var rows = 0;
// ca
for (let rows = 0; rows <= 10; rows++) {
    document.write('<tr>');
    for (let cols = 0; cols <= 10; cols++)
        document.write('<td>' + rows + ',' + cols + '</td>')
}

if (rows === 0 && cols === 0) {
    document.write('<td>' + blank + '</td>')
}

about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

"What am I doing wrong?" A lot.

You should think about what you are trying to do first, before going at it.

Your html table is ill-formed, you don't even close the <tr> tags.

for (let row = 0; row <= 10; row++) {
    document.write('<tr>');
    for (let col = 0; col <= 10; col++) {
        if (row == 0 && col == 0) {
            document.write('<td>x</td>');
        }
        else if (row == 0) {
            document.write('<td>' + col + '</td>');
        }
        else if (col == 0) {
            document.write('<td>' + row + '</td>');
        }
        else {
            document.write('<td>' + row * col + '</td>');
        }
    }
    document.write('</tr>');
}

Try it here.

about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!