Return a Value in Javascript

Tell us what’s happening:
I’m not getting it

Your code so far


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

// Only change code below this line
 function timesFive(a) {
   a = 5;
   return a * 5; 
 }

 function timesFive(a) {
   a = 2;
   return a * 5; 
 }

 function timesFive(a) {
   a = 0;
   return a * 5; 
 }


console.log(minusSeven(10));
console.log(timesFive());
console.log(timesFive());
console.log(timesFive());

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.98 Safari/537.36.

Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/basic-javascript/return-a-value-from-a-function-with-return/

Functions are reusable pieces of code that can do something for you (i.e. some work, example multiply something by 5). In order to make them reusable they need to be able to work regardless of the context. This is where parameters come in. Parameters are just empty boxes that you define during the function definition. Each time you call a function to do some work for you, you pass it a different something, different data. I.e. timesFive(2) and that something fills in those empty boxes, so a = 2 automatically, you don’t have to do anything. Subsequently, it proceeds to multiply the passed data a times 5 and returns 10.

I hope this helps. Remember, the goal is for your functions to be reusable in many cases, regardless of what data is passed to it during the function call.

1 Like

Thanks. This helped. now i’ve gotten it