Is there any other way to do a return statement other than discussed in the above thread?

Is there any other way to do a return statement other than discussed in the above thread?
0

#1

Continuing the discussion from freeCodeCamp Challenge Guide: Return a Value from a Function with Return:

function timesFive (bum) { return bum * 5;}

I was specifically wondering if num is a reference word.

I am not sharing this as the forum as I view the problem solving skills required as everyones own journey :-):sunglasses:

Is the short answer: because this is the way the language works?


#2

As you notice, I changed num to bum and still got the challenge correct.


#3

Yes bum is just what you’re calling the input you give to the function. When you invoke the function you are most certainly passing some value into the function. The function uses your declaration to see what you want to do with the input and then uses return as a way to output whatever you did to the data. You can call it whatever you want which is why whether it is a num or a bum it works.


#4

No.

Yes.

You can give it (almost) any name you like. You can then use that name to access what is passed to the function.

So if you call timesFive(3), it will give bum the value of 3.


#5

Can you write what your example would output, the written code? If you don’t mind to illustrate…


#6

Running timesFive(3) is the same as running the inner part of your function with bum = 3. Since the only line of code is: return bum * 5; which is: return 3 * 5; it will return 15.


#7

Here is the full code:

function minusSeven(num) {
  return num - 7;
}

// Only change code below this line

function timesFive (bum) { return bum * 5;}

Where are you getting 3 from?


#8

This is the bottom part (from lesson 164)

function timesFive (bum) { return bum * 5;}
timesFive(3);

Why am I getting 25 instead of 15?


#9

Can you put your code in a jsbin or something for us to look at?


#10

Is that like an online editor?


#11

Yes it’s jsbin.com just type the code you wrote and share the link.


#13

Just copy and paste all of the code in a reply. Make sure to put 3 backticks on the line before and the line after the code, so that it retains the formatting you used in your code.


#14

Again, this is from lesson 164


// Example

function minusSeven(num) {
 
 return num - 7;

}

// Only change code below this line

function timesFive (bum) { return bum * 5;}

timesFive(3);

#15

So you’re wondering why num stores whatever value you pass to it?


#16

I think so. Is that because num refers to the math library on javascript?


#17

If your code is as you have it above, you will get 15 and not 25.


#18

No it’s because num is a parameter of the function. It’s your way of passing input to the function to do something with it. In this case you’re taking the input and and multiplying it by 5. SInce the input you pass in is 3 (indicated when you invoked the function with the line “timesFive(3);”), you’re really saying 3 * 5 which is 15.


#19

#20

return5

Here is another image:


#21

I tried to share it on a javascript editor and it did not work. the online editor is saying it is coming out to 25 still…