Global variables not working?


#1


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


The error code keeps telling me that I don't have a variable called hungry declared, but as far as I can tell, I do. What am I missing?


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

var eat = function() {
  // Add your if/else statement here!
  if (hungry = true && foodHere = true){
      return true;
  }
  else{
      return false;
  }
};


#2

Be sure to use the comparison operator, ===.

Is this the one that one set to true and the other false? That one uses an OR operator if I recall.


#3

Ah, that fixed it. Thanks!

And no. That's the next exercise.


#4

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