11. And


#1

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

Help guys! What am I doing wrong?


var hungry = true
var foodHere = true

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


#2

Instructions:

Create two variables, hungry and foodHere, and set them both equal to true. Inside the eat function, create an if statement that returns true only if both hungry and foodHere are true, and false otherwise. The function eat should take no input and hungry and foodHere should both be globals.

What are you doing:

console.log(true); // Oops!

#3

OK, what if I wanted it to print true?


#4

var result = // call function;
console.log(result); // yay!

#5

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

};
what's wrong with this?


#6

Missing a starting brace for the if block.


#7

same problem here for me.


#8

You have to return true/false instead of printing strings.


#9

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