11. And


#1

Here is my code:
var hungry = true;
var foodHere = true;

var eat = function() {
if(hungry && foodHere)
{
console.log("Well go get something to eat.");
return true
} else if(!(hungry && foodHere)){
console.log("well move on with your day then!");
return false

}// Add your if/else statement here!
else {
return("if your hungry why don't you want to get food?");
}

};

It outputs:
well move on with your day then!
well move on with your day then!
Well go get something to eat.

but it lets me continue to the next lesson. Something doesn't seem right about that. Could anyone educate me on this?


#2

Good evening! Here's my code,
Codecademy lets me continue too (without any output).
Maybe, it'll be helpful fot you :smile:

var hungry = true;
var foodHere = true;

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


#3

If I take out the console.log parts in my code it lets me continue without an output as well.


#4

So I think i figured it out or just got it to do what I wanted it to do without understanding it completely, but here is my code.

var hungry = true;
var foodHere = true;

var eat = function() {
if(hungry && foodHere)
{
console.log("Well go get something to eat.");
return true
}
else {
return false
}
};

It outputs: "Well go get something to eat."


#5

+++++ truth table
I created the so-called truth-table's

=======================
  AND  | true  | false
 ------|-------|-------
 true  | true  | false
 ------|-------|-------
 false | false | false
 ------|-------|-------

#6

Hey Chip,

I think console.log() was not intended to be used with this assignment, so it's not displaying the right responses. As it is, we're not really sure what they are specifically testing for to let us move on, so that may have something to do with why we don't see what we would be expecting. If I had to guess they test the else if 2 different ways and never touch the if portion of it, but who knows.

That said, your syntax is slightly off a bit; you're missing a semi-colon after your returns in the if and else if portion of your script. Resolving these issues doesn't change the logs the console shows, but worth mentioning nonetheless.