Learn Introductory JavaScript by Building a Pyramid Generator - Step 54

Tell us what’s happening:

I’ve gone through 6 forums now and found similar problems. I’ve change my arguments and made sure the return is a mathematical return. My const is the only thing I question but the error is that I need to use addTwoNumbers as my function, which I have. I’ve reset the lesson 3 times and input the same thing but continue to get the same error.

Your code so far

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

function padRow(name) {
  return name;
}

// User Editable Region

function addTwoNumbers(num1,num2) {
  num1 = 5;
  num2 = 10;
  return num1 + num2;
};
const sum = addTwoNumbers(num1,num2);
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

Challenge Information:

Learn Introductory JavaScript by Building a Pyramid Generator - Step 54

You aren’t passing arguments to the function correctly.

You can’t pass num1 and num2 as arguments to the function, since those variables don’t exist outside the function.

How would I get them to exist outside the function? Creating a ‘const’ or ‘let’ for them?

like this?
var num1 = 5;

var num2 = 10;

function addTwoNumbers(num1,num2) {

num1 = 5;

num2 = 10;

return num1 + num2;

};

const sum = addTwoNumbers(num1,num2);

console.log(sum);

They don’t need to exist outside the function at all. They take the values that you pass to the function as arguments.

I get the error of return should be the sum of 2 numbers with this opotion:

function addTwoNumbers() {

return 5 + 10;

}

const sum = addTwoNumbers();

console.log(sum);

Your function should have 2 parameters.

This function should take two arguments

The function needs to add any two numbers. Your function only adds 5 and 10.

Call the function with 2 numbers.

calling your addTwoNumbers function with 5 and 10 as the arguments

You should call your function with the arguments 5 and 10, but it should also work with 1 and 2 or 30 and 40.

const sum = addTwoNumbers();

You are calling your function with zero arguments.

1 Like

Thank you so much. I was overthinking it for some reason and was thinking I needed a const over a var.

1 Like

Overthinking it is so often the case!

Only advice I can give is to read each line of the instructions carefully and make sure you’ve implemented each one. Really take it step by step. You could even re-write the instructions as bullet points if it helps.

  • Declare a function named addTwoNumbers.

  • This function should take two arguments and

  • return the sum of those two arguments.

  • Then 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.

1 Like

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.