11. And


#1

what am I missing in my code?

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

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

else
{ console.log (false);
}

};


#2

It could be a simple as a missing function call:

eat()

What error messages are you seeing?


#3

I have the same issue.

var hungry = true;
var foodHere = true;

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

my console displays both:
true
false

the error message is
Oops, try again. It looks like your function doesn't return false when hungry is false

But I don't know why


#4

Quotation marks on the Boolean primitives is the issue.


#5

Thank you for that!

I'm still getting the same error message
Oops, try again. It looks like your function doesn't return false when hungry is false.


#6

Implies an expected return value from the function that is not undefined. This can be solved by returning an object rather than logging it.

// ... 
{
    return true;
} else {
    return false;
}

#7

Thanks so much! It works now!


#8

Haha yeah I also made that mistake :slightly_smiling:


#9

Hi, could you help me? I don't understand what is wrong) My code:
var hungry = true;
var foodHere = true;
var eat = function(hungry,foodHere) {
if (hungry && foodHere){
return true;
} else {
return false;
}
};

Error:
It looks like your function doesn't return true when hungry and foodHere are both true.


#10

Let the variables exist as globals.

var eat = function() {

#11

Thank you so much for your answer) It works now!:slightly_smiling:


#12

You seem to know alot...can you help me with this?

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

#13

Take out the = true part and it will be a valid expression. When both operands are true the expression yields true. We don't need a comparator. JavaScript evaluates each as a Boolean.

Only that there is a lot that I don't know. Did you know that all the visible and detectable matter in the known universe makes up only 5% of its mass? I use that analogy to describe my ignorance. We never know more than we can comprehend, and of that, we understand half.


#14