Back to Freecodecamp

Step 94

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

latest1.1 KB
Original Source

--description--

Your pyramid generator is still working. However, it could be possible to end up with an infinite loop again.

Because you are only checking if done is not equal to count, if done were to be larger than count your loop would go on forever.

Update your loop's condition to check if done is less than or equal to count.

--hints--

Your while loop should check if done is less than or equal to count.

js
assert.match(__helpers.removeJSComments(code), /while\s*\(\s*done\s*<=\s*count\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));
}*/

--fcc-editable-region--
let done = 0;

while (done !== count) {
  done++;
  rows.push(padRow(done, count));
}
--fcc-editable-region--

let result = ""

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

console.log(result);