Coddeacademy Control Flow in JS step 11 AND : what is the solution?


#1



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

Oops, try again. Did you set hungry equal to true?


Replace this line with your code.


#2

Hi,

Please paste in your code so we can help you accordingly !
We don't give the code rather help you to solve it by guiding you.


#3

var hungry = "true";
var foodHere = "true";
console.log(hungry+foodHere);

var eat = function() {
if(hungry && foodHere) {
console.log(hungry+foodHere);
console.log("Its time to eat");
}
else { console.log("Time to eat false");
}
// Add your if/else statement here!

};


#4

Oops, try again. Did you set hungry equal to true? is the errror message

Thanks


#5

true and false are booleans so you don't add quotes around them

Have a look at this part of the instructions:

Inside the eat function, create an if statement that returns true only if both hungry and foodHere are true, and false otherwise.

What you are returning is incorrect


#6

If I take away the quotes the value changes to 1 for each variable.


#7

sorry i don't understand you


#8

var hungry = true;
var foodHere = true;
console.log(hungry+foodHere);

var eat = function() {
if(hungry && foodHere) {
console.log(hungry+foodHere);
console.log("Its time to eat");
}
else { console.log("Time to eat false");
}

};

The resuits:

2
Time to eat false

the var hungry and foodHere come out as 1 and 1 not as true and true?


#9

This part is correct..

var eat = function() {
 
};

No on your lesson remove everything but the function and two variables, then read your instruction again and add in your if/else function you need to return not console.log


#10

var hungry = true;
var foodHere = true;

var eat = function() {
if hungry && foodHere
{
return("Its time to eat");
}
else { return("Time to eat false");
}

};

Still wrong: It gives SyntaxError: Unexpected identifier


#11

Your condition needs to be in parenthesis ( )
you need to return true for if statement and false for else statement

also when you return the result shouldn't be in ( )


#12

var hungry = true;
var foodHere = true;

var eat = function() {
if (hungry && foodHere)
{
return("Its time to eat");
}
else {
return("Time to eat false");
}

};

Result message:Oops, try again. It looks like your function doesn't return false when hungry is false.


#13

You need to return true for if statement and false for else statement

also when you return the result shouldn't be in ( )

Like this:

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

#14

go it :wink:nnnnnnn

thanks


#15

got it :wink:

thanks