lundi 18 mars 2019

&& operator in if statement with for in loop is not giving right answer

I have cart system for a website I made. I'm currently trying to create a meal deal discount in the checkout page. I've put together an if statement but its not quite working. see below:

for (var i in cartArray) {
                        if((cartArray[i].name=="Shampoo") &&
                        (cartArray[i].name=="Drinks Can") &&
                        (cartArray[i].name=="Small Brush"))
                        {
                        console.log("yes");
                        } else {
                        console.log("no");
                        
                        }
                }

I get '3 no' in the console but when I use the OR operator it works. But that won't do as I need the code to recognize all 3 simultaneously so I can proceed further with the discount. Thank you in advance.

Aucun commentaire:

Enregistrer un commentaire