Back to Freecodecamp

Step 105

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

latest1.2 KB
Original Source

--description--

Use a multi-line comment to comment out this loop as well, to prepare for the next approach.

--hints--

Your for loop should be commented out using multi-line comment.

js
assert.lengthOf(code.match(/\/\*\s*for\s*\(/g), 2);
assert.lengthOf(__helpers.removeJSComments(code).match(/for\s*\(/g), 1);

Your for loop body should be commented out as part of multi-line comment.

js
assert.notMatch(code, /\/\/\s*rows\.push/);
assert.lengthOf(code.match(/rows\.push/g), 3)
assert.notMatch(__helpers.removeJSComments(code), /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));
}*/

/*while (rows.length < count) {
  rows.push(padRow(rows.length + 1, count));
}*/

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

let result = ""

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

console.log(result);