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