Back to Freecodecamp

Step 65

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

latest1.5 KB
Original Source

--description--

Remember in an earlier step, you learned about return values. A function can <dfn>return</dfn> a value for your application to consume separately.

In a function, the return keyword is used to specify a return value. For example, this function would return the value given to the first parameter:

js
function name(parameter) {
  return parameter;
}

Use the return keyword to return the value of the character variable, repeated rowNumber times.

--hints--

You should use the .repeat() method.

js
assert.lengthOf(__helpers.removeJSComments(code).match(/\.repeat\(/g), 2);

You should use the .repeat() method on your character variable.

js
assert.lengthOf(__helpers.removeJSComments(code).match(/character\.repeat\(/g), 2);

You should pass rowNumber to your .repeat() call.

js
assert.match(__helpers.removeJSComments(code), /character\.repeat\(\s*rowNumber\s*\)/);

You should use the return keyword.

js
assert.match(__helpers.removeJSComments(code), /return/);

You should return the result of your .repeat() call.

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

--seed--

--seed-contents--

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

--fcc-editable-region--
function padRow(rowNumber, rowCount) {

}
--fcc-editable-region--


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

let result = ""

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

console.log(result);