Error message for 11


#1

Guys, what is wrong with my code below. This is for 11.
I need help understanding what am doing wrong, as it keep saying:
"Try Again, It looks like your function doesn't return false when hungry is false."


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

var eat = function(hungry, foodHere) {
  // Add your if/else statement here!
  if (hungry && foodHere) {
      
      return "Come in and get your tommy filled";
      
  } else {
          return "We are a hospitable zone, enjoy your time here!";
          }
  
};


#2

you already took two global varibale hungry and foodHere

var eat = function(hungry, foodHere) // don't need any patameter

so just write

var eat = function() {  // without patameter

function should return true or false nothing else.

see instructions


#3

Thanks rcodeman for replying.
I already did that before, it didn't work. Tried again now and same result.

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

var eat = function() {
// Add your if/else statement here!
if (hungry && foodHere) {

  return "Come in and get your tommy filled";

} else {
return "We are a hospitable zone, enjoy your time here!";
}

};


#4

if (hungry && foodHere) {

  return "Come in and get your tommy filled";  // here write return true

if (hungry && foodHere) {
return true;

#5

To be honest, still not getting this.
I think my code is right but still getting error message that i Function doesn't return false.


#6

why did you write Come in and get your tommy filled ???????

instead of just write return true nothing else

Come in and get your tommy filled // remove it from your code


#7

I understand your frustration. Previous lessons had you type out a string to output, but in this particular exercise you need to simply type it like this (no strings):

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

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

Hope that helps!


#9

It's working now. :slight_smile:


#10

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