More on control flow in JS


#1

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

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

};
eat();

I'm getting this error..
Oops, try again. Did you declare a variable called foodHere?please anyone can help?


#2

hi,

var foodhere =true;// Declared variable is all in lowercase

in the if/else statement:

if(hungry && foodHere) // variable is lowerUpper case

Not sure if that will resolve the problem its just something I noticed in the code


#3

yes yes...that was only the mistake...solved...
thank you


#4

great nothing like code not working and not know why! Its week 2 for me and still so much to learn!! all best with rest of you lessons I think you are a bit further ahead than me


#5

Ya..I am just starting code your own adventure 2.


#6

ur on a roll then...I am just getting to where I think you were attempting this task earlier (lesson 11?) trying to complete this section then I can start code your own adventure tomoz


#7

by any chance can you help with #10? I cant seem I
get it right :frowning:


#8

@byteace95016

sorry I just seen the msg I was away from JS for the last two days.. have you managed to fix your error now?

If not...have a look at these two pieces of code to compare with your own and see if they can help?
If you are still stuck post your code so someone can take a look and give you some feedback

// Complete lines 3 and 4!

var iLoveJavaScript = true;
var iLoveLearning = true;

if(iLoveJavaScript && iLoveLearning) {
  // if iLoveJavaScript AND iLoveLearning:
  console.log("Awesome! Let's keep learning!");
} else if(!(iLoveJavaScript || iLoveLearning)) {
  // if NOT iLoveJavaScript OR iLoveLearning:
  console.log("Let's see if we can change your mind.");
} else {
  console.log("You only like one but not the other? We'll work on it.");
}

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

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


};
eat();

// e remembers to add three back ticks ` b4 and after the code that e posts on the forum

output:
code 1:
Awesome! Let's keep learning!

code 2:
true


#9

This code worked for #10:

var iLoveJavaScript = true;
var iLoveLearning = true;

if(iLoveJavaScript && iLoveLearning) {
// if iLoveJavaScript AND iLoveLearning:
console.log("Awesome! Let's keep learning!");
} else if(!(iLoveJavaScript || iLoveLearning)) {
// if NOT iLoveJavaScript OR iLoveLearning:
console.log("Let's see if we can change your mind.");
} else {
console.log("You only like one but not the other? We'll work on it.");
}