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

186
Views
I am trying to use a for loop in javascript to create a a table that displays * and for each row the columns increase by 1 *
***let numRows = 5;
let numColumns = 10;
let strRowOutput = "";
for (let row = 1; row <= numRows; row++) {
    for (let column = 1; column <= numColumns; column++) {
        strRowOutput += "*";
    }
    console.log(strRowOutput);
    strRowOutput = "";
}
console.log();***

thats the code so far but it only displays the last row with 10*.enter image description here

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

The second for loop condition should be dependent to the variable in first for loop like column <= row OR if you want to restrict the column to a maximum value, you can use column <= Math.min(row, numColumns)

Im using the second approach here

Working fiddle

let numRows = 5;
let numColumns = 10;
let strRowOutput = "";
for (let row = 1; row <= numRows; row++) {
  for (let column = 1; column <= Math.min(row, numColumns); column++) {
      strRowOutput += "*";
  }
  console.log(strRowOutput);
  strRowOutput = "";
}
console.log();

about 4 years ago · Juan Pablo Isaza 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!