11. And


#1

Hello, I'm having syntax issues again.

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

var hungry = true
var eatHere true

var eat = function() {
if (hungry && eatHere);
}
{
else (hungry || eatHere);
}


#2

Hi!

You are missing you assign syntax here:

Put the equal to =


#3

OH man, of all the mistakes!!! However, still getting syntax error:

var hungry = true
var eatHere = true

var eat = function() {
if (hungry && eatHere);
}
{
else (hungry || eatHere);
};


#4

I'll first advise you end your variables definition with a semi-colon.

Also, don't forget the return statements requested in each block. For the if, add

return true;

and for the else, add

return false;

while you remove this.

because you only want

return false;

otherwise.


#5

OK, I see about he returns. I am not sure how to use the return false; with nothing for else.

var hungry = true;
var eatHere = true;

var eat = function() {
if (hungry && eatHere)
return true;
}
{
else() <==== what goes here?
return false;
};


#6

So, you should have it as:

else {
  return false;
}

each condition stays in its block (curly braces).


#7

OK. This is still not working. What am I missing? (thank you so much, btw!):

var hungry = true;
var eatHere = true;

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


#8

Also, the directions say:

"The function eat should take no input and hungry and foodHere should both be globals."

....and I wonder if I am making a mistake with global vs. local?


#9

Yeah! You have used a variable name wrongly. Replace all eatHere with foodHere

var hungry = true;
var foodHere = true;

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

#10

OK.
For syntax, I don't understand whey the curly brackets close at the end of both blocks instead of in between each block.

var hungry = true;
var foodHere = true;

var eat = function() {
if (hungry && foodHere)
return true; <=== whey not a } here?
else {
return false;
} <=== insted of the } here?
};


#11

My bad! I wrote that too quickly.

var hungry = true;
var foodHere = true;

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

Each curly brace for a block and then, one for the whole function.


#12

NP - thank you for your help!!
:grinning:


#14