Returns Confusion


#1

Hi guys, I'm not quite sure what's wrong here or even what the meaning of the error is.

I get this error: > Oops, try again. Hmm, it looks like your quarter function doesn't return -25 for -100.

I know that I fix it by adding 'return' and it's fixed but nothing in the theory bar explains what and how to use 'return'. And what does it mean by 'doesn't return -25 for -100'? I feel like I missed reading something?

// Define quarter here.
var quarter = function(number) {
    
    number / 4

}

if (quarter(120) % 3 === 0 ) {
  console.log("The statement is true");
} else {
  console.log("The statement is false");
}

#2

your quarter function returns nothing at all, it computes a value and that value is never used again. Add a return statement before this value to make it usable. This way the use of quarter(x) would have a value of x/4.


#3

Gotcha. So what's the difference between 'returning' a function as opposed to 'calling' it?


#4

Well function are sub programs that are not immediately executed. So these bunches of code just lie around and wait for a start command. And that start command is called function call: functionName()
Now you jump to the sub program and execute the tasks given there and when you're finished doing this you need to return to the main program and that is done by return. Side note: if you don't use return javaScript adds it automatically at the end of the program. So when you use return it is mostly to either exit early or to send a value from the function to the calling scope, which is what you're doing here.