Back to Freecodecamp

Step 76

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

latest1.0 KB
Original Source

--description--

Comments can be helpful for explaining why your code takes a certain approach, or leaving to-do notes for your future self.

In JavaScript, you can use // to leave a single-line comment in your code.

Add a single-line comment above your for loop to remind yourself to change the code to a different kind of loop.

--hints--

You should start a single-line comment with //.

js
assert.match(code, /\/\//);

Your single-line comment should be at least five characters long.

js
assert.match(code, /\/\/.{5,}/);

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

--fcc-editable-region--

for (let i = 1; i <= count; i++) {
  rows.push(padRow(i, count));
}
--fcc-editable-region--

let result = ""

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

console.log(result);