Learn Introductory JavaScript by Building a Pyramid Generator - Step 95

Tell us what’s happening:

How can l set my loop’s condition to run when i is greater than 0?

Your code so far

const character = "#";
const count = 8;
const rows = [];

function padRow(rowNumber, rowCount) {
  return " ".repeat(rowCount - rowNumber) + character.repeat(2 * rowNumber - 1) + " ".repeat(rowCount - rowNumber);
}

// TODO: use a different type of loop
/*for (let i = 1; i <= count; i++) {
  rows.push(padRow(i, count));
}*/

/*while (rows.length < count) {
  rows.push(padRow(rows.length + 1, count));
}*/


// User Editable Region

for (let i = count; false; false) {
  
}

// User Editable Region


let result = ""

for (const row of rows) {
  result = result + "\n" + row;
}

console.log(result);

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:126.0) Gecko/20100101 Firefox/126.0

Challenge Information:

Learn Introductory JavaScript by Building a Pyramid Generator - Step 95

Hello @Samuel18,

Try reviewing how a for loop is defined.

Your for loop is currently set to start iterating with i = 8, but it has no limiting value and no incrementing value (i.e. i will never increase) and so there is no loop.

Check out this article(JavaScript Loops Explained: For Loop, While Loop, Do...while Loop, and More)

Does this help?

2 Likes

thank you, it passed