Learn Introductory JavaScript by Building a Pyramid Generator - Step 103

Tell us what’s happening:

Whats wrong with this code. Not sure why it doesn’t work

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

// 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) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/130.0.0.0 Safari/537.36

Challenge Information:

Learn Introductory JavaScript by Building a Pyramid Generator - Step 103

Hello @booleanmethod9,

In this step you need to update i = i - 1 statement to use subtraction assignment (-=) operator.

An example can be:

const someArray = [1, 2, 3, 4, 5];
for (let j = someArray.length; j >= 0; j -= 1) {
  // Do some operation
}

If you get stuck, you can reset the step and start from scratch.

Happy coding!

But thats not the subtraction assignment operator

1 Like

Your expression shouldn’t have more than one equals sign.

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Subtraction_assignment

I made a mistake in my explanation. I updated it. You can check the updated version.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.