Learn Introductory JavaScript by Building a Pyramid Generator - Step 103

Tell us what’s happening:

Subtraction assignment doesn’t seem to work? The only line I’ve changed from the last lesson is
(i=i-=1) to (i = i -=1) but it keeps giving me the message “Your for loop should use subtraction assignment to reduce i by 1.”

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

// User Editable Region

  result = result + "\n" + row;
}

console.log(result);

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/127.0.0.0 Safari/537.36

Challenge Information:

Learn Introductory JavaScript by Building a Pyramid Generator - Step 103

Hi. The original was i = i - 1. Think now you can do the same with the assignment operator -=

the -= should be used instead of the =
Example: this x -= 10 gives the same result as writing x = x - 10

Which line am I supposed to replace? Because I’ve done the second, then the third, then both and nothing is working :confused:
Things I’ve tried: (…i -= i - 1), (…i -= 1), (i = i -= 1), ( i -= i -= 1)[I knew the last one wasn’t going to work but i’ve been stuck for a full day now]

Its a formatting thing, I had a semicolon inside my brackets…

1 Like

This is the only place where subtraction occurs in the editable region, so it’s probably the subtraction that the instructions want you to update