OK - kind of a different 'help' question


#1

So I am up to 10.5 - the instructions are to add logical operators (&& or ||) to the code quiz I have been writing. My question is not how the operators work, but how I can use them in my quiz.

This is what I wrote. So far, everything is working.

var user = prompt("What's on the boob tube? What geek TV show do you want to watch tonight?").toLowerCase();
switch(user) {
case 'GAME OF THRONES':
console.log("No! I haven't read the latest book. NO SPOILERS!!");
break;
case 'DOCTOR WHO':
console.log("Doctor Who without David Tenant should just.not.exist!");
break;
case 'THE WALKING DEAD':
console.log("Ugh! That show is gross AND boring in equal measures!");
break;
case 'STAR TREK':
console.log("Star Trek is soooo 20th century.")
break;
case 'THE VAMPIRE DIARIES':
console.log("Do I LOOK like a 13 year old emo kid??");
break;
default:
console.log("Huh? I never even heard of that show...");
}

But I'm stumped as to how I could use a logical operator in the quiz itself. All my questions are basic call/responses. The suggestion in the tutorial couldn't work in this quiz. I don't want to have to rewrite a whole new program at this point. Any suggestions?


#2

Well I don't know if this helps but you can do something like:

case 'GAME OF THRONES' && 'THE WALKING DEAD' || 'DOCTOR WHO':

Switch Statements work rather similarly like if statements, they're just a lot cleaner if you're finding comparisons for one variable. 'user'


#3

Nevermind, I got this to work:

var day = true;
var time = true;

var user = prompt("What geek TV show do you want to watch tonight?").toUpperCase();
switch(user) {
case "GAME OF THRONES":
if(day && time) {
console.log("No! I haven't read the latest book. NO SPOILERS!!");
} else
{
console.log("That's not on tonight.");
}
break;
case "DOCTOR WHO":
if(day || time) {
console.log("Doctor Who without David Tenant should just.not.exist!");
} else {
console.log("That's not on tonight.");
}
break;
case "THE WALKING DEAD":
console.log("Ugh! That show is gross!");
break;
case "STAR TREK":
console.log("Star Trek is soooo 20th century.");
break;
case "THE VAMPIRE DIARIES":
console.log("Do I LOOK like a 13 year old emo kid??");
break;
default:
console.log("Huh? I never heard of that show...");
}

Thanks for the suggestion anyway.