Logical operators && and ||?


Im not sure why but I get this message. Oops, try again. Make sure to use at least one logical 'and' (&&)!
Am I not using the && and || right?

var user = prompt("Do you like potatos?").toLowerCase();
        case 'no':
          if(user === 'no'){
            console.log("I don't like them either!");
        case 'yes':
          if(user === 'Yes' || user === 'yea'){
            console.log("Who are you?");
        case 'sometimes':
            console.log("I like them in certain things too");


Well, it doesn't look like you have used && at all? You have used || . So maybe your problem is you just need to include && somewhere


This has been confusing to me. How come the && would work and not the ||. Do they not go in the same spot as the && would go, or set up the same way?


Well let me give you an example from my code. I think see it used will give you an idea of how it works and what it works with.

switch(user) {
    var BRAD = BRAD
        console.log("That is my name too!");
        } else {
        console.log("Your name is close to my name!");}
        if (Brad||Braden){
        console.log("That is my name too!");
        } else {
        console.log("Our names are very close!");}

So basically, && is used as to say if the person types in brad and stew in the console they will get back that is my name too! but if not then you get another sentence. In the second if statement, if the person puts in brad or braden then you get that is my name too! else you get something else. As you can see you sortof use it like and and or in sentences @blogninja19450


So I don't need to add the === after my var, to check if it's equal?


I don't believe so because the user data doesn't have to equal that. It is just when it does equal that it needs to be noticed and thus get another sentence. Hopefully that is decent enough in explaining it... If not, I can get another help desker, super user or mod to help explain it


Ok thanks. Also in this lesson do I need to add another var asking the user another question?


No what you have is fine! I just went about it a slightly different way than you. :smiley: In fact, I needed to get rid of that var Brad = 'Brad' statement so don't go down that path haha


Alright! But I managed to put another one in and it seemed to work anyways! Thanks!
it works both ways!


Good! Glad you figured it out and hopefully the rest of your coding is less confusing! :smiley:


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