Back to Freecodecamp

Step 52

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

latest1.3 KB
Original Source

--description--

When you have a value that is explicitly written in your code, like the "Hello!" string in your function, it is considered to be <dfn>hard-coded</dfn>. Hard-coding a value inside a function might not make it as reusable as you'd like.

Instead, you can define <dfn>parameters</dfn> for the function. Parameters are special variables that are given a value when you call the function, and can be used in your function to dynamically change the result of the function's code.

To add a parameter to your function, you need to add a variable name inside the parentheses. For example, this demo function has a name parameter:

js
function demo(name) {

}

name sounds like a useful parameter, so go ahead and add it to your padRow function.

--hints--

Your padRow function should have a name parameter.

js
assert.match(padRow.toString(), /\(name\)/);

--seed--

--seed-contents--

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

--fcc-editable-region--
function padRow() {
  return "Hello!";
}
--fcc-editable-region--
const call = padRow();
console.log(call);


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