Console.log followed by return


#1


https://www.codecademy.com/en/courses/javascript-beginner-en-qDwp0/2/2?curriculum_id=506324b3a7dffd00020bf661


Hello,
if I use the code below, I get the following output in the console in the upper right :
get some food
nope
nope
get some food
true

I don't understand this weird order... I just expected to get once the answere "get some food" and with "return" the function would be stopped. I guess this behaviour is because of the use of console.log. Am I not allowed to combine console.log followed by return, as shown in the example below?
Thanks already in advance for helpful comments.

Pius


// Declare your variables here!
var hungry = true;
var foodHere = true;

var eat = function() {
  // Add your if/else statement here!
  if (hungry && foodHere){
      console.log("get some food");
      return true;
  } else { 
      console.log("nope");
      return false;
  }
};

eat();


#2

This has to do with the exercise, see what happens when you run it here, just press the run button in the top right


#3

Thank you for the fast and helpful answer!


#4

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.