Logical operation


#1

// Declare your variables here!
var hungry;
var foodHere;

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

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


#2

you should set the values for hungry and foodHere here:

var hungry;
var foodHere;

and then pass them (hungry and foodHere) as arguments in the function call


#3

// Declare your variables here!
var hungry= true;
var foodHere = true;

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

ERROR MSG: Oops, try again. It looks like your function doesn't return true when hungry and foodHere are both true.


#4

that is weird, anyway, the exercise wants you don't use function parameters and function arguments. It wants you to access the global variable directly.


#5

how can that be done...


#6

by removing the function parameters and arguments:

var eat = function()

(you can remove the arguments). functions have access to global variables (hungry and foodHere)


#7

that works..thank for guidance


#8