More on Control fk


#1

// Declare your variables here!
var hungry = true;
var foodHere = true;
var eat = function() {
// Add your if/else statement here!
if(hungry && foodHere) {
return "false";
}else {
return "true";
}
};
can somebody tell what correction can be done here ?

the computer is telling "Oops, try again. It looks like your function doesn't return false when hungry is false."

Replace this line with your code.


#2

if(true && true) {
return "false"; // return false ??? 
}else {
// one of both var are false and here is the return true??? 
return "true";
}

Rethink that :slight_smile:


#3

Can you give me a
Better explanation


#4

Instructions

Create two variables, hungry and foodHere, and set them both equal to true.

var hungry = true;
var foodHere = true;

You did it correct.

Inside the eat function, create an if statement that returns TRUE only if BOTH hungry and foodHere are TRUE

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

Why did you return FALSE if both variables are TRUE

And why did you return TRUE if one of both are FALSE

else {
// one of both var are false and here is the return true??? 
return "true";
}

#5

STILL I AM GETTING IT WRONG
HERE'S MY CODE
var hungry = true;
var foodHere = true;
var eat = function() {
if(hungry&&foodHere) {
return "true";
} else {
return "false";
}
};


#6

true and false should be as a Boolean expression.

we use " " for string

and if lesson wants then you can call the function.


#7

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