More on Control Flow in JS - And


#1

I am confused with the code below, as it says: "Oops, try again. Did you declare a variable called hungry?"

Could you please help me with this problem?
Thanks

var hungry = true;
var foodHere = true;

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

Replace this line with your code.

`
Continuing the discussion from More on control flow in JS:


#2

Hi this part

if(hungry && foodHere = true)

instead of = put ===


#3

clear that, but now I have the following code, and the computer says: "Oops, try again. It looks like your function doesn't return false when hungry is false."
Why?

var hungry = true;
var foodHere = true;

var eat = function() {
if(hungry && foodHere === true) {
return "true";
} else { return "false";
}
};


#4

then remove the " " around true and false


#5

cool, thx :slight_smile:


#6

Do you need === true? I mean it's the same thing as just

if (hungry && foodHere)

right? Sure it will still work but I think they covered that if you put an if statement it will look at it as true unless you state otherwise.