AND exercise


#1

Where is the error in this code?

var hungry = true
var foodHere = true

var eat = function() {

if (hungry && foodHere === true); {
return true;
} else {
return false;
}
};


#2

Hi this part remove the ; after the if condition

if (hungry && foodHere === true); <==this one

#3

Just did it and it works. Thanks a lot! But I have no clue why this makes a difference? What does the ; do then which makes it return an error?


#4

you could read about it in this topic..


#5

@robertkooyman Also, considering you understand if (hungry) I think you could go with foodHere in place of foodHere === true. (disclaimer: I'm not as familiar with && and || as @wizmarco is; hopefully he'll weigh in if I'm wrong :wink:)


#6

Hi yes @msfrisby he could... but the Lesson want him to use the comparator &&..


#7

Thanks, @wizmarco! :smiley:

I did mean I wasn't totally sure if if (hungry && foodHere) was valid.
But dang! Why do I barely remember this lesson?? Maybe I need to take it again :computer::pencil2: