Back to Freecodecamp

Step 101

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

latest1.1 KB
Original Source

--description--

Your iteration statement is also going to be different. Instead of adding 1 to i with each loop, you need to subtract 1.

Like you did earlier with i = i + 1, update your iteration statement to give i the value of subtracting 1 from itself.

--hints--

Your for loop should use i = i - 1 as the iteration.

js
assert.match(__helpers.removeJSComments(code), /for\s*\(\s*let\s+i\s*=\s*count\s*;\s*i\s*>\s*0\s*;\s*i\s*=\s*i\s*-\s*1\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);
}

// 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));
}*/

--fcc-editable-region--
for (let i = count; i > 0; false) {

}
--fcc-editable-region--

let result = ""

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

console.log(result);