The "AND" logical operator


#1

<PLEASE USE THE FOLLOWING TEMPLATE TO HELP YOU CREATE A GREAT POST!>

<Below this line, add a link to the EXACT exercise that you are stuck at.>

<In what way does your code behave incorrectly? Include ALL error messages.>
SyntaxError: expected expression, got keyword ‘else’

```

var eat = function() {

var hungry = true ;
var foodHere = true ;

if(hungry && foodHere) {
return true;

else
return false;

};

<do not remove the three backticks above>

#2

I cannot seem to figure out what I cam doing wrong. I am using the previous example to help me and I still can’t do it.

PLEASE HELP.


#3

@willbakerman

missing syntax mainly braces {}


if(what you are comparing) { 
 do this first;
}else {
otherwise do this;
};

#4

I still seem to get an error message.

SyntaxError: missing } after function body


#5

Paste in your updated code


#6

Don’t forget to put another

} after the one that closes the if/else to close the eat function


#7

var eat = function() {

var hungry = true ;
var foodHere = true ;

if(hungry && foodHere){
return true ;

} else { return false;

};


#8

see my last comment :slight_smile:


#9

I still can’t seem to pass??
Here is my code:

var eat = function() {

var hungry = true ;
var foodHere = true ;

};

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

};
This is my error

SyntaxError: return not in function


#10

Should look like this, you had the right syntax mostly but now you’ve seemed to have thrown braces all over the place


var eat = function() {

var hungry = true ;
var foodHere = true ;

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

#11

I have now added this code:

var eat = function() {

var hungry = true ;
var foodHere = true ;

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

And I get this message: Oops, try again.
Did you declare a variable called hungry?

It looks correct to me??


#12

Hi these variables

var hungry = true ;
var foodHere = true ;

should be outside the function eat()


#13

What do you mean by this??

I have written this:

var eat = function() {
};

var hungry = true ;
var foodHere = true ;


#14

like this


var hungry = true ;
var foodHere = true ;

var eat = function() {

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

#15

I see, I see!!

Thank you very much for all of your help!

The small errors are the most frustrating.


#16