Back to Freecodecamp

Step 98

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

latest1.0 KB
Original Source

--description--

That's a very clean and functional loop. Nice work! But there's still more to explore.

Use a multi-line comment to comment out your while loop.

--hints--

Your while loop should be commented out.

js
const stripped = __helpers.removeJSComments(code);
assert.notMatch(stripped, /while/);

Your while loop body should be commented out.

js
const stripped = __helpers.removeJSComments(code);
assert.notMatch(stripped, /rows\.push/);

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

--fcc-editable-region--
while (rows.length < count) {
  rows.push(padRow(rows.length + 1, count));
}
--fcc-editable-region--

let result = ""

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

console.log(result);