Back to Freecodecamp

Step 92

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

latest1.1 KB
Original Source

--description--

Since you have moved the comparison into the while condition, you can remove your entire if statement.

--hints--

You should no longer have an if statement.

js
assert.notMatch(__helpers.removeJSComments(code), /if\s*\(\s*done\s*===\s*count\s*\)/);

You should no longer set continueLoop to false.

js
assert.lengthOf(__helpers.removeJSComments(code).match(/continueLoop\s*=\s*false/g), 1);

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

let continueLoop = false;
let done = 0;

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

let result = ""

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

console.log(result);