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

202
Views
I'm trying to create a star pyramid which should contain 1 * in the first row, 2* with equal spaces in the second row, like wise 3rd and 4th row

    [enter image description here][1]

List item

    let x = 4;
    let text = "";
    for(let i = 1; i <= x; i++) {
        for(let j = 1; j <= x - i; j++) {
            text += " ";
        }
        for(let k = 0; k < 2 * i - 1; k++) {
        text += "*";
        }
        text +="\n";
    }
    console.log(text);

---Output I want is like this. I'm new to this. Thank you in advance [1]: https://i.stack.imgur.com/AJvaZ.png

about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Small change:

let x = 4;
let text = "";
for(let i = 1; i <= x; i++) {
    for(let j = 1; j <= x - i; j++) {
        text += " ";
    }
    text += "*";
    for(let k = 0; k + 1 < i; k++) {
        text += " *";
    }
    text +="\n";
}
console.log(text);
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!