So, generally you want your functions to use return.
But, for this challenge, the instructions want you to make a function that
accepts two arguments and outputs their sum to the dev console
This means that you need a console.log() inside of your function.
The behaviour of the function needs to match exactly the requirements. Our tests check the behaviour of the function and not the behaviour of the function and other code you write alongside the function.
in your IDE, but the test isn’t basing what it checks on those bottom two lines. (You could delete them or change them.) The test is sending its own values to functionWithArgs and seeing if that function sends anything to the console.
Thank you guys for trying to explain what happens and I’m sorry if I didn’t make myself clear as I am confused already.
I guess all I wanna know is when to use Return in general, not because it is required by a challenge or exercise? Because I’ve been reading a lot of tutorials and I always see them using return.
You will almost always use return. A console.log() just prints out the values, but a return statement lets other parts of your code use the returned value.
Just to expand on what Jeremy is saying, it really depends on what you need. If you need a function that sums to numbers and logs it out, then the first version would be good, but I would call the function something like logSum. If all you want is the sum of two numbers, then I’d use the second call it getSum or something else descriptive.
Both are completely valid ideas. In the real world, I would expect more things like the latter example, but for this challenge, they wanted something that does what the former does.