Learn Introductory JavaScript by Building a Pyramid Generator - Step 102

Tell us what’s happening:

// running tests

  1. Your for loop should call rows.push().
  2. You should call padRow() in your .push() call.
  3. You should pass i as the first argument to your padRow() call.
  4. You should pass count as the second argument to your padRow() call.
    // tests completed
    // console output

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; i > 0; i--) {
 rows.push(padRow(i, count));
}

// User Editable Region


let result = ""

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

console.log(result);

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36

Challenge Information:

Learn Introductory JavaScript by Building a Pyramid Generator - Step 102

In the for loop, you decremented i by writing i--. The lesson was expecting you to write i = i - 1, and will teach you i-- soon after. Make that change and you should be good.

This is one of those cases where you didn’t really do anything wrong, but you did something that the automatic tests didn’t expect or account for because the lesson didn’t teach it to you yet, and the automatic tester is unfortunately returning a hint that has nothing to do with it.

Edit: reversed the order of the paragraphs

1 Like