Back to Freecodecamp

Step 68

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

latest1.2 KB
Original Source

--description--

You should now see the same bunch of characters in your console. Your padRow function is doing the exact same thing you were doing earlier, but now it's in a reusable section of its own.

Use the addition operator to concatenate a single space " " to the beginning and end of your repeated character string.

Remember that you can use the + operator to concatenate strings like this:

js
" " + "string"

--hints--

You should concatenate a single space to the beginning of your returned value.

js
assert.match(padRow(1, 1), /^\s/);

You should concatenate a single space to the end of your returned value.

js
assert.match(padRow(1, 1), /\s$/);

Your padRow() function should return the repeated character series with a space before and after the series.

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

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