Learn Introductory JavaScript by Building a Pyramid Generator - Step 55

Tell us what’s happening:

hi, pls help i get stuck for a long time in here

this is the issue:
3. Your function should not return a hard-coded value. That is, it should work with any two number arguments.
6. You should assign sum the value from calling the addTwoNumbers function with 5 and 10 for the arguments

thks bforee

### Your code so far


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

function padRow(name) {
  return name;

// User Editable Region

}

function addTwoNumbers(a, b){
  return sum
}
let a = 5
let b = 10
const sum = (a+b)
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 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/128.0.0.0 Safari/537.36

Challenge Information:

Learn Introductory JavaScript by Building a Pyramid Generator - Step 55

Hi Your code does work but it’s not in the format they have asked. You have hard coded values defined as variables, It should work when you pass any value into a and b, the perameters.

Look carefully at the syntax of the example and try and do it like that. You are not returning words but numbers so write a calculation in the body of the function.

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

sayName("Camper", "Cat");
1 Like

Hi there,

Let’s do this step by step.

Step 1:

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

There are some terms you need to get familiar with.
Let’s take a look at the code above:

This is a function definition, or how to declare a function.

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
padRow("Jane") and padRow("Peter") are function call
"Jane" and "Peter", the specific values of name in function call, is called argument

Sometimes, the term argument can be interchangeable with the term parameter.

A function can take more than one argument. For example:

function hello(first_name, last_name) {
   return "Hello " + first_name + " " + last_name;
}

Base on these information. I hope you can write addTwoNumbers function definition like the instruction asked.

Step 2:

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.

At this step, you need to declare a variable name sum and then assign (=) it to the function call of a function addTwoNumbers with 2 arguments: 5 and 10.

2 Likes

So, I have three ways how to approach this.

  1. You can move the sum variable inside the function, such that it calculates and returns the sum. Then inside the console log call the addTwoNumbers() function with the two parameters a and b.
  2. You can move all the variables inside the function, only leaving the console log, and then delete the function parameters since they are already declared. Finally, to see your results call your function in the console log. Remember to call the function with parenthesis, otherwise the console will display the name of the function rather than the function results.

However, despite all these being corrected the editor will not accept them. there are instructions to follow and the editor expects your code to follow the instructions structure.

According to the instructions:

  1. You should have a function, with two parameters, you can give them whatever name you want. Inside the function, you should return the sum of the two parameters.

All this should be done outside the function.

  1. Then declare a sum variable and assign it the function call, plus the arguments 5 and 10.
  2. Lastly, Console your sum variable.
1 Like

Thanks for yours reply and solution but now the issue change:

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

Can you post your updated code?

here is my updated code:

function addTwoNumbers(a,b) {

return (a + b)

}

let a = 5

let b = 10

const sum = (a + b)

console.log(sum)

Okay, so you defined addTwoNumbers function. Now you can use it to get the sum of any two numbers using function call and arguments.

For example:

addTwoNumbers(1, 1) wil return 2
addTwoNumbers(1, 2) wil return 3

Now, how to get the sum of 5 and 10.

And assign the returned value (the sum) to the sum variable you declared.

You can take a look at the code on line 10 as a reference:

const call = padRow("CamperChan");