Create two variables, hungry and foodHere, and set them both equal to true. Inside the eat function, create an if statement that returns true only if both hungry and foodHere are true, and false otherwise. The function eat should take no input and hungry and foodHere should both be globals.

ERROR : SyntaxError: expected expression, got keyword 'else'

var hungry=true;
var foodHere=true;

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



Not so necessary. You are going to check that truth statement in your condition. The below should suffice.

if (hungry && foodHere)


Thankyou for the reply.

I did as you instructed but still getting the same error .



Okay, you should remove the first curly brackets you closed on if return statement and put at the end to have:

var eat = function() {

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


THANKS a lot! That helped although i dont understand why wont it accept the curly brackets which are normally used after the if statement. :smile:


Normally? The instance of use is what matters. The function was to check if that was true; or, it returns false if it's not. More like an alternative.

Hope this helps! :slight_smile:


when do you not use curly brackets on the if statements? So confused


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