Questions about two of the lesson here

I am doing a recap of the lessons here but, there are something that bugs me about it. Could anyone explain as to why?

How is this requirment fuffiled?

functionWithArgs(7,9) should output 16 .

If i console.log it like

functionWithArgs(7, 3);
//This will console log 10 but, not 16

Why do I have to use

var answer = timesFive(5); // 8
I understand that we assing a new variable and assing it to the new value's we have created.
 but cant i use
console.log ( timesFive);
and would it only give me
[Function: timesFive] why doesn't it give me the nubers.

Here you are doing Addition Operation
“functionWithArgs(7,9)” should output ‘16’
7 + 9 = 16

functionWithArgs(7, 3);
//This will console log 10 but, not 16
Because 7+3 = 10 Not 16.
I Hope you got the clarity.

1 Like

No not really thanks for the reply thou. I think you missunderstood my question
It answers just why there is a 10
but not how it passes the test after the requirment is not meeted??

It is not giving you the number because you have not invoked the function. If you have a function definition

  function plusThree(num) {
            return num + 3;
}

The above function takes in an argument, adds three to it and returns the answer. It can only do that if you invoke or call it like plusThree(7). Where it will take 7, the number you passed as an argument adds three to it and returns the answer 10.
If you want to access the returned value, you assign it to a variable like
const answer = plusThree(7) and console.log(answer) it or access it directly like console.log(plusThree(7)).
However not all functions have explicit return values. If you don’t tell the function to return a value, it will return the default return value undefined. For example,

  function  myFunction(arg1, arg2){
                      console.log(arg1, arg2);
                          }

will return undefined because you haven’t instructed it to return a value. Therefore if you call/invoke it like myFunction(1, 5) , it will console.log 1 and 5 but returns undefined.
If you do this console.log(plusThree), you haven’t invoked(called ) the function. You are console logging the function itself.

2 Likes