#5 Logical Operators, I need help.. =(


#1

I've been on this section for a week now. I can figure out what I'm doing wrong. First thing is the .toUpperCase(); It was giving me errors so I took it out. After that I think I was doing everything correctly. I guess not. Can someone help.. Thx in advance.. Here is my code:

var user = prompt("Your looking for an adventure this weekend. Do you drive a NASCAR, fly a FA-18 fighter JET, or go SKY diving?");

switch(user) {
   case 'nascar':
       var driving = prompt("Are you a good fast driver?", "(YES or NO or OK)");
          if (driving === yes || driving === ok) {
             console.log("You got 1st place! Job well done!");
         } else {
             console.log("Sorry you placed last!");
}
break;
   case 'jet':
     console.log("Ok Maverick, lets suit up!");
     var fly = prompt("Two questions. Do you know how to fly and are you afraid of heights?);
         if (fly === yes && fly === no || fly === yes && fly === yes) {
             console.log("You fly like Ice Man!!")
         } else {
             console.log("Weeeeeee... SPLAT!");
}

break;
    case 'sky':
       console.log("Weeeeee Splat!!");
break;
    case 'all':
       console.log('Ok, then, when?');
break;
    default:
       console.log('Go away if you dont understand the question');
}


#2

Hey @jaepark75! Firstly dont forget to select over your code and hit CTRL + K to format your code so we can identify your code-error quickly. There is only one problem! You forgot to finish your quotation marks! Ima spot the problem for you!

Here is where the problem is:

Just change it to :smile:

var fly = prompt("Two questions. Do you know how to fly and are you afraid of heights?");

And you will be fine! If there is still some problems concerning you please reply saying so!


#3

Thank You for the quick reply. That did help but I'm running into problems in the first option. When it prompts the first question and I choose "nascar" it prompts me to the next question... when I answer "yes" it says this

if I I'm not sure when to hit command K. In here where I'm writing now or when I'm working on the lessons.


#4

You need to change all those answers as a string. :smile:

Like, they're not variables or values or keys or etc etc etc.... :smiley:

So every answer you get from the prompt must be a string.

"yes"
"no"
"ok"


#5

Ok @jaepark75! I see your problems why do you have two strings???

Right here

Just put it as one string like this:
var driving = prompt("Are you a good fast driver? , (YES or NO or OK)");

Another one is in the if and else statement you didnt define the if statement as a string.

Problem:

Should be like this:
if (driving === "yes" || driving === "ok") {
console.log("You got 1st place! Job well done!");

Do the same thing for all of them.

Thirdly this is just additonal but lowercase the anwser so it actually goes to your if statement

By doing the method .lowerCase();

Like this:

Any problems now?


#6

Oh i didnt see your post @ragezapper! Sorry!


#7

I fixed all the mistakes that you guys pointed out. I cant believe I didnt pick that up!! I'm running into a problem when I put the .lowerCase();


#8


#9

Sorry again i messud up with the Java. In java ts .lowerCase(); , but in Javascript it is .toLowerCase(); Sorry! And if you want uppercase, you do .toUpperCase();

Here is the documentation.


#10

Dont be sorry. Now my next problem is the result of going thru this.. In the var fly = blah blah.. if else statement (yes && no || yes && no) its supposed to console.log( you fly like Ice Man ). Instead if console.log( Weeeeeee.... SPLAT! )

Do you know whats wrong with the code there?


#11

A ScreenShot would be Lovely! Couldnt understand your problem correctly!


#12


#13

Can you try removing that .toLowerCase(); maybe that is the problem!


#14

Well, since there's only one prompt... there can only be one answer....

I suggest you put another prompt and put another variable to say yes, no, yes and no, yes and yes, no and no, etc etc.

And .toLowerCase();

Does work, just an FYI


#15

Hi will you or someone help me debug my code please Thank you in advance.:

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

switch(user) {
case 'purple':
if(purple && blue your favorite color) {
console.log("Purple is my favorite color too!")
}
else {
console.log("Bless your heart.");
}
break;
case 'blue':
console.log("Blue is cool for the ocean.");
break;
case 'red':
console.log("Do you squirm at the sight of blood?");
break;
default:
console.log("I don't know if that is a color.");
}


#16

@frenchaire

If you have a problem, please post this in a new thread with your question + code + error message in order to keep the forum clean.


#17

I got the code to run by changing a few things:
var user = prompt(
"You're looking for an adventure this weekend. Do you drive a NASCAR, fly a FA-18 fighter JET, or go SKYdiving?"
);
switch (user) {
case 'nascar':
var driving = prompt("Are you a good fast driver?", "(YES or NO or OK)");
if (driving === true || driving === false) {
console.log("You got 1st place! Job well done!");
} else {
console.log("Sorry you placed last!");
}
break;
case 'jet':
console.log("Ok Maverick, lets suit up!");
var fly = prompt(
"Two questions. Do you know how to fly and are you afraid of heights?"
);
if (fly === true && fly === false || fly === true && fly === true) {
console.log("You fly like Ice Man!!");
} else {
console.log("Weeeeeee... SPLAT!");
}
break;
case 'sky':
console.log("Weeeeee Splat!!");
break;
case 'all':
console.log('Ok, then, when?');
break;
default:
console.log('Go away if you dont understand the question');
}