Java, section 11


#1

Keeps telling me my function doesn't return false when my hunger variable is set to false. Although the console.log output I get with it is to my false condition, despite both variables set as true.
`

Replace this line with your code.

var hungry=true;
var foodHere=true;

var eat = function() {
if(hungry && foodHere){console.log( 'time to eat than fucker!');}
else{console.log('execute you starving to death motherfucker!!');}

};

getting playfully colorful with my return statements. But yea, please help! :slight_smile:


#2

Hey! The reason it's not working for you is because you're logging a string to the console when you run your code, instead of returning a boolean.

var hungry=true;
var foodHere=true;

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

The code above will work for you. If you need further clarification, let me know and I'll be happy to help you


#3

Yup, that did it! Umm, without setting the expectations you explain all nuances, I would appreciate any length winded response to...this arrangement of code is familiar from past exercises but I'm not sure I've ever understood the reasoning. My tendency is to attempt verbalizing the process and, I don't quite see why a string or Boolean values differ within the function since it still all seems contingent by the global variable values. IOW the true/false is determined before it gets to the return portion so...I'm feeling like the question is already falling apart. Lol. More mileage and syntax recognition perhaps? I am pretty confused by the real distinction between console.log n return. Again, I can kind of intuit when to use, but I'll be damned if I really know the distinction. Any info is appreciated but, regardless thanks for the correct input. On with the show now!

   Thanks!

Justin

----- Reply message -----


#4

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