Unexpected identifier


#1

`var hungry = true;
var foodHere = true;

var eat = function() {
if hungry && foodHere = true {
console.log("True")
}else{
console.log("False")
};'
Not working


#2

You have a couple problems

  • Your if statement isn't using proper syntax. The condition should be in parenthesis ()....
  • Your condition is wrong, it's assigning instead of evaluating, you should change the = to === also make sure to evaluate the variable hungry as well.
  • You need to close your function with at curly bracket at the end.

#3

Hi there!
Don't know if you mean to put the ' at the beginning and end, but I don't believe that should be there :smile:

your if statement should look like:
if (hungry && foodHere) {
console.log("true");
} else {
console.log("false");
};

you don't need to type hungry && foodHere === true, because it will automatically assume it is true!

Hope this helps


#4

@conolyb1 @bytemaster18011 Didnt work what you guys said it made it worse
`var hungry = true;
var foodHere = true;

var eat = function() {
if (hungry && foodHere === true) {
console.log("true");
} else {
console.log("false");
}
};`
Look at the code and see what I am doing wrong


#5

@codeace40947, from what it looks like you didn't do what @bytemaster18011 asked you to.


#6

if (hungry === true && foodHere === true) {
 // you could also use  (hungry && foodHere) as a shortuct.

Fix your if statement


#7

@lolman @bytemaster18011 @conolyb1
'var hungry = true;
var foodHere = true;

var eat = function() {
if (hungry && foodHere) {
console.log("true");
} else {
console.log("false");
}
};`
Look at this


#8

Ok question,

Are you adding the backtick " ` " directly in your code?

'var hungry = true;
var foodHere = true;

var eat = function() {
 if (hungry && foodHere) {
console.log("true");
} else {
console.log("false");
}
};`

Because if that's what your code looks like that's where your problem is, it should look more like this:

var hungry = true;
var foodHere = true;

var eat = function() {
 if (hungry && foodHere) {
console.log("true");
} else {
console.log("false");
}
};

#9

Your code is now correct:

but you have to call your eat function... so add

var hungry = true;
var foodHere = true;

var eat = function() {
if (hungry && foodHere) {
console.log("true");
} else {
console.log("false");
}
};

eat();

#10

@lolman @conolyb1 @bytemaster18011
var hungry = true;
var foodHere = true;

var eat = function() {
if (hungry === true && foodHere === true) {
console.log("true");
} else {
console.log("false");
}
};

eat();
Still doesn't work


#11

I had to look up this lesson...
Your syntax is now correct however the lesson asks you to return a value not console.log it, sometimes you just have to re-read the instruction to make sure you're doing what it's asking :smile:

so...
change the console.log expression to a return expression...

var hungry = true;
var foodHere = true;

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

#12

Thanks, that helped and i should have check the directions carefully