Learn Introductory JavaScript by Building a Pyramid Generator - Step 55

Tell us what’s happening:

I do not know what to do. I unknowingly keep making mistakes.

Your code so far

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

function padRow(name) {
  return name;
}

// User Editable Region

function addTwoNumbers(){
  return sum;
}
const sum = addTwoNumbers(5,10);
console.log(sum);

// User 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 + "\n" + row;
}

console.log(result);

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36 Edg/126.0.0.0

Challenge Information:

Learn Introductory JavaScript by Building a Pyramid Generator - Step 55

The function should have two parameters, and then, the sum of these two parameters should be returned (literally). So, instead of ‘sum’ return e.g. arg1 + arg2.

I still do not get it.

What is the purpose of this function?

We provide 2 numbers, and the result we get back is the sum of those 2 number, right?

So what is the 2 numbers here?

And you:

but what is sum? And sum of what?

You should go back to the previous step 54 to understand about function, argument and parameter.

Just saying you don’t understand each step seems to not be helping you. I would try talking to us about how you are stuck. Actually talking about the code is hard but it’s really helpful for us and for your learning.

What you think of a more specific question? Hard to know what you don’t understand.

ex.
What is the difference between parameters and arguments?
What is a sum?

I do not know how to get the sum to be added and returned. I tried arg1 and arg2 like DobarBREND told me to, but that didn’t work either. What should my code look like?

Let’s take a look at the padRow function above:

This function take one parameter: name, and return back that parameter.

padRow("Jane") will return "Jane"
padRow("Peter") will return "Peter"

name is called parameter
"Jane" and "Peter" is called argument


Now, you have to write addTwoNumbers function that take 2 parameters and return the sum of those 2 parameters. So that:

addTwoNumbers(1, 2) will return 3
addTwoNumbers(2, 3) will return 5


Note: you can name your parameters whatever you like as long as it’s a valid variable name .


How to get the sum of 2 numbers?
Well, to get the sum of 1 and 2, we use: 1 + 2. You get the idea.

How to return that sum?
Use the keyword return

I have tried that and the only problem now is that the function should return the sum of the two numbers. Here is my code so far:

function addTwoNumbers(sum) {

return sum;

}

const sum = addTwoNumbers(5 + 10);

console.log(sum);

As I said, addTwoNumbers function should take 2 parameters.
These 2 parameters must be separated by a comma (,)

Look at the function call:

addTwoNumbers(1, 2)

There are 2 arguments: 1 and 2, separated by a comma (,)

it’s not:

addTwoNumbers(1 + 2)

Now, look at your function. Your function only have 1 parameter.

Please read a bit more about functions and it will help you solve this