2. If / else if / else

Why do I have to use return instead of console.log in this exercise? Can someone explain the difference between console.log and return? I know console.log logs things onto a console for debugging purposes but I don’t see how it makes a difference if we return something or console log it because wouldn’t the console.log information also appear on the black part of the screen (sorry, I forgot what that part is called)

For reference, here is my code:

var isEven = function(number) {
// Your code goes here!

if(number % 2 === 0){
return true;

else if (isNaN(number)){
return (“Your input is not a number”); <— How come I have to use return here not console.log?

else {
return false;



1 Like

This is where the program of codeacademy is confusing you, it’s simply displaying your JS, but in reality this wouldn’t be the same.

Console.log outputs your result to the console, however return returns a value from a function within the script. So while the difference here is irrelevant if codeacademy is simply showing you the result of both, one sends a value from the script to the console, the other returns a value within the script to be used.

If you had simply used console.log in the function, you wouldn’t return any value from it at the end of a condition.

Learn return
Learn console.log()

1 Like

Thanks! That makes a lot of sense. Just so I am clear - Does that mean that when I console.log something in real life, the result only goes to the console and won’t show up on the screen?

Correct. So if we’re speaking in a real world sense, applying a value into an actual website, you would user a method such as innerHTML on an element to set the html element contents to a value (this is beyond this websites JS exercises).

Though the lessons have you using prompts and the console for now, it’s rarely something you would use for other reasons than troubleshooting.

SO hello
may i ask what website do you suggest when one completes this site? and does your consideration include the payed version as well