Back to Freecodecamp

Step 55

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

latest2.0 KB
Original Source

--description--

Before moving on, take a moment to review how functions work.

Declare a function named addTwoNumbers. This function should take two arguments and return the sum of those two arguments.

Your function should not use hard-coded values. An example of a hard-coded function might be:

js
function sayName(firstName, lastName) {
  return "John Doe";
}

sayName("Camper", "Cat");

This function would return "John Doe" regardless of the arguments passed to the parameters firstName, and lastName, so "John Doe" is considered a hard-coded value.

Declare a sum variable and assign it the value of calling your addTwoNumbers function with 5 and 10 as the arguments. Log the sum variable to the console.

--hints--

You should have a function called addTwoNumbers.

js
assert.isFunction(addTwoNumbers);

Your function addTwoNumbers should have two parameters.

js
assert.lengthOf(addTwoNumbers, 2);

Your function should return the sum of the two parameters.

js
assert.strictEqual(addTwoNumbers(5,10), 15);

Your function should not return a hard-coded value. That is, it should work with any two number arguments.

js
assert.strictEqual(addTwoNumbers(3, 5), 8);

You should declare a sum variable.

js
assert.isDefined(sum);

Your sum variable should have the value 15.

js
assert.strictEqual(sum, 15);

You should assign sum the value from calling the addTwoNumbers function with 5 and 10 for the arguments.

js
assert.match(code, /sum\s*=\s*addTwoNumbers\s*\(/);

You should log your sum variable.

js
assert.match(code, /console\.log\(\s*sum\s*\)/);

--seed--

--seed-contents--

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

function padRow(name) {
  return name;
}
--fcc-editable-region--

--fcc-editable-region--

const call = padRow("CamperChan");
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);