5. Logical Operators


#1

what is wrong with my code?

var user = prompt("Do you enjoy Deez Nuts?").toUpperCase();

switch(user) {
case "YES":
console.log("Give this man a beer.");
var type = prompt("Corona or Budlight?").toUpperCase();
var types = prompt("Coster?").toUpperCase();
if(type = "YES" || types = "YES") {
console.log("Thanks, for the positive feedback.");
} else {
console.log("I'll get right on it");
}
break;
case "NO":
console.log("No beer for you.");
break;
case "WHAT":
console.log("Don't be playin games with me.");
var explain = prompt("You have hearing aids?").toUpperCase();
var explains = prompt("Are you tired?").toUpperCase();
if(explain = "NO" && explains = "NO") {
console.log("I don't understand people like you.");
} else {
console.log("Ok, I'll give you a break.");
}
break;

 default:
  console.log("I don't understand the answer" + user + "try again");

}


#2

Line 12 & 25: Replace every "=" with "==".

The "=" operator is an assigment operator. It sets a value to what is left to it.
The "==" operator is a comparison operator. It compares the value on it's left with the value on it's right.


Another operator similar to "==" is the "===" operator.
Differences:
"==": Cares just for the value.
"===": cares for the value and the type.

More on operators: http://www.w3schools.com/js/js_operators.asp


#3

So I should replace all the = with == for lines 12 through 25?


#4

Never mind I got it, I had to replace all the = with == for the statements with the || and && operators.

thanks