5/6 Logical Operators


#1

Add some if/else statements to your cases that check to see whether one condition and another condition are true, as well as whether one condition or another condition are true. Use && and || at least one time each.

var user = prompt("What is your favorite color?").toUpperCase();

var redBlue = prompt("Do you like RED and BLUE?").toUpperCase();
if(redBlue === 'YES'){}
else{}

var pinkRed = prompt("Do you like PINK or RED?").toUpperCase();
if(pinkRed === 'PINK'){}
else if(pinkRed === 'RED'){}
else{}

switch(user) {
case 'RED':
if(red && blue = true) {
console.log "The 4th of July colors"
}
else {
console.log "These are other colors that have nothing to do with the 4th of July, unless it is white."
}
console.log("You like the color of strawberries.");
break;
case 'BLUE':
console.log("You like the color of the sky.");
break;
case 'PINK':
if(pink || red = true) {
console.log "Those are Valentine Day colors."
}
else {
console.log "These colors have nothing to do with Valentine's Day."
}
console.log("You like the a girly color.");
break;
default:
console.log("You like other colors of the rainbow.");
};

Oops, try again. Your code doesn't look quite right. Check the error message for more info: ReferenceError: Invalid left-hand side in assignment

ReferenceError: Invalid left-hand side in assignment


#2

Inside conditions use "===" instead of "=". A single equal sign is used for variable assingments. Inside conditions you want to use the comparison operator "===".


#3

In addition to what @schamanu already said, your if/else statements are empty

And you are comparing some variables, that do not exist in your code.

And again like @schamanu said the conditions use === equal signs and follow this pattern:

if (red === "Yes" && blue === "Yes") {
    do something;
}

#4

I reworked most of what you said.Can you check what is wrong again?

var user = prompt("What is your favorite color?").toUpperCase();

switch(user) {
case 'RED':
if(red === "Yes" && blue === "Yes") {
return "The 4th of July colors"
}
else {
return "These are other colors that have nothing to do with the 4th of July, unless it is white."
}
break;
case 'BLUE':
return("You like the color of the sky.");
break;
case 'PINK':
if(pink || red === true) {
return "Those are Valentine Day colors."
}
else {
return "These colors have nothing to do with Valentine's Day."
}
break;
default:
return("You like other colors and shades of the rainbow.");
};


#5

Nevermind this is the correct code

var user = prompt("What is your favorite color?").toUpperCase();

switch(user) {
case 'RED':
if(red === "Yes" && blue === "Yes") {
console.log ("The 4th of July colors")
}
else {
console.log ("These are other colors that have nothing to do with the 4th of July, unless it is white.")
}
break;
case 'BLUE':
console.log ("You like the color of the sky.");
break;
case 'PINK':
if(pink || red === true) {
console.log ("Those are Valentine Day colors.")
}
else {
console.log ("These colors have nothing to do with Valentine's Day.")
}
break;
default:
console.log ("You like other colors and shades of the rainbow.");
};