Back to Freecodecamp

Step 69

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

latest1.0 KB
Original Source

--description--

Now it is time for a bit of math. Consider a three-row pyramid. If we want it centered, it would look something like:

md
··#··
·###·
#####

Empty spaces have been replaced with interpuncts, or middle dots, for readability. If you extrapolate the pattern, you can see that the spaces at the beginning and end of a row follow a pattern.

Update your blank space strings to be repeated rowCount - rowNumber times.

Open up the console to see the result.

--hints--

You should call .repeat() on your " " strings to repeat them rowCount - rowNumber times.

js
assert.equal(padRow(1, 3), "  #  ");

--seed--

--seed-contents--

js
const character = "#";
const count = 8;
const rows = [];

--fcc-editable-region--
function padRow(rowNumber, rowCount) {
  return " " + character.repeat(rowNumber) + " ";
}
--fcc-editable-region--

for (let i = 0; i < count; i = i + 1) {
  rows.push(padRow(i + 1, count));
}

let result = ""

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

console.log(result);