11. And


#1

Mysterious Syntax Error?

I require advice with:

  1. More on Control Flow in JS
  2. And exercise

Error message: "Oops, try again. There was a problem with your syntax."

var hungry = true;
var foodHere = true;

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

Link to exercise: https://www.codecademy.com/courses/javascript-beginner-en-qDwp0/2/2?curriculum_id=506324b3a7dffd00020bf661

Thank you for taking the time to help me!


#2

Try this code...

var hungry = true;
var foodHere = true;

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

}

function eat should not be anonymous and don't include the '=' sign while returning true or false in a function

Actually, you can use an anonymous function here , the only error was in your syntax was the

 return = true and return = false

it should be

return true and return false

#3

i am trying to understand task but i am so stupid
1 - code

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

};
eat(hungry,foodHere);

second

var hungry  = true;
var foodHere = true;
var eat = function(lhungry,lfoodHere) {
    if ( (lfoodHere = true) && (lhungry = true)) 
    {
    
        hungry = false;   //food eaten, hunger disappeared   
        foodHere = false;
    }
    else
    {
        hungry = lhungry;
        foodHere = lfoodHere;
    }
      
  // Add your if/else statement here!
  
};

what it wants from me, I know what I'm doing, but I do not understand the task and error messages

och i am soo good, its work

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

#4

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