Back to Freecodecamp

Step 72

curriculum/challenges/english/blocks/learn-introductory-javascript-by-building-a-pyramid-generator/660f3915b41a441537ec9f5e.md

latest1.1 KB
Original Source

--description--

Because you are only increasing i by 1, you can use the <dfn>increment operator</dfn> ++. This operator increases the value of a variable by 1, updating the assignment for that variable. For example, test would become 8 here:

js
let test = 7;
test++;

Replace your addition assignment with the increment operator for your loop iteration.

--hints--

Your for loop should not use addition assignment with i.

js
assert.notMatch(__helpers.removeJSComments(code), /i\s*\+=\s*1/);

Your for loop should use the increment operator on i.

js
assert.match(__helpers.removeJSComments(code), /i\s*\+\+/);

--seed--

--seed-contents--

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

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

--fcc-editable-region--
for (let i = 0; i < count; i += 1) {
--fcc-editable-region--
  rows.push(padRow(i + 1, count));
}

let result = ""

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

console.log(result);