5. Logical operators: always default outcome?


#1

var user = prompt("Do you want to go to London? Ther are three means of transportation which are an aeroplane, a cuise and a freighter. Which kind of transportation do you want to go to?").toUpperCase();

switch(user) {

case 'aeroplane':
    var first_class = prompt("Do you want a first class? Do you have quite lots of money?(Yes or No) ").toUpperCase();
    var business_class = prompt("Well, although this class isn't quite expensive, not cheap. Nevertheless are you OK?").toUpperCase();

    if(first_class === yes || buisness_class === yes){
        console.log("Billiant!! It's awesome!!");
    } else {
        console.log("Awww!! Why not?? It's not an economy calss");
    }
        break;

case 'cuise':
    var suite_room = prompt("Do you want very romantic mood? Right?").toUpperCase();
    var single_room = prompt("Althought not bad, do you really enough? Are you sure?").toUpperCase();

    if(suite_room === yes || single_room === yes){
        console.log("What a amazing plan! You can take such a romentic time. However, it'll take a bit long time.");
    } else {
        console.log("Again?? Why?? What are problems?? Then What do you want?");
    }
        break;

case 'freighter':
    var vessel = prompt("What?? Do you want to attempt a stow away?").toUpperCase();
    var ship = prompt("why would you do that? Do you think that is exciting?").toUpperCase();

    if(vessle === yes && ship === yes){
        console.log("Are you serious? I swear what you must stop this!!");
    } else {
        console.log("Oh!! Good on you!!");
    }
        break;

default:
    console.log("What else?");

}

What should I fix for it?


#2

@magastory,
First you toUpperCase() your =user= variable
and
then in your switch you use all-lowercase CASE clauses....


#3

You mean like this?

var user = prompt("Do you want to go to London? Ther are three means of transportation which are an aeroplane, a cruise and a freighter. Which kind of transportation do you want to go to?").toUpperCase();

switch(user) {

case 'aeroplane':
    var first_class = prompt("Do you want a first class? Do you have quite lots of money?(Yes or No) ").toLowerCase();
    var business_class = prompt("Well, although this class isn't quite expensive, not cheap. Nevertheless are you OK?").toLowerCase();

    if(first_class === yes || buisness_class === yes){
        console.log("Billiant!! It's awesome!!");
    } else {
        console.log("Awww!! Why not?? It's not an economy calss");
    }
        break;

case 'cruise':
    var suite_room = prompt("Do you want very romantic mood? Right?").toLowerCase();
    var single_room = prompt("Althought not bad, do you really enough? Are you sure?").toLowerCase();

    if(suite_room === yes || single_room === yes){
        console.log("What a amazing plan! You can take such a romentic time. However, it'll take a bit long time.");
    } else {
        console.log("Again?? Why?? What are problems?? Then What do you want?");
    }
        break;

case 'freighter':
    var vessel = prompt("What?? Do you want to attempt a stow away?").toLowerCase();
    var ship = prompt("why would you do that? Do you think that is exciting?").toLowerCase();

    if(vessle === yes && ship === yes){
        console.log("Are you serious? I swear what you must stop this!!");
    } else {
        console.log("Oh!! Good on you!!");
    }
        break;

default:
    console.log("What else?");

}


#4

@magastory,

 var user = prompt("Do .....to go to?").toLowerCase();

switch(user) {

case 'aeroplane':
    //your code
        break;

case 'cruise':
    //your code
        break;

case 'freighter':
   // your code
      break;

default:
    console.log("What else?");
}

#5

I tried before and then the error message has appeared..T^T
Like this..

Oops, try again. Your code doesn't look quite right. Check the error message for more info: ReferenceError: yes is not defined


#6

@magastory,
If the Javascript Interpreter encounters yes without any double- or single- quotes
for the interpreter yes will be a variable which it will try to evaluate to a VALUE....

You will have to encapsulate all of your yes'ses in either single- or double-quotes
like

"yes"

#7

It's working but not quite much;;; Its answer always same when I put there which is yes or no.;;


#8

@magastory,
present the your FULL code which you are using now.....


#9

var user = prompt("Do you want to go to London? Ther are three means of transportation which are an aeroplane, a cruise and a freighter. Which kind of transportation do you want to go to?").toLowerCase();

switch(user) {

case 'aeroplane':
    var first_class = prompt("Do you want a first class? Do you have quite lots of money?(Yes or No) ").toUpperCase();
    var business_class = prompt("Well, although this class isn't quite expensive, not cheap. Nevertheless are you OK?").toUpperCase();

    if(first_class === 'yes' || buisness_class === 'yes'){
        console.log("Billiant!! It's awesome!!");
    } else {
        console.log("Awww!! Why not?? It's not an economy calss");
    }
        break;

case 'cruise':
    var suite_room = prompt("Do you want very romantic mood? Right?").toUpperCase();
    var single_room = prompt("Althought not bad, do you really enough? Are you sure?").toUpperCase();

    if(suite_room === 'yes' || single_room === 'yes'){
        console.log("What a amazing plan! You can take such a romentic time. However, it'll take a bit long time.");
    } else {
        console.log("Again?? Why?? What are problems?? Then What do you want?");
    }
        break;

case 'freighter':
    var vessel = prompt("What?? Do you want to attempt a stow away?").toUpperCase();
    var ship = prompt("why would you do that? Do you think that is exciting?").toUpperCase();

    if(vessle === 'yes' && ship === 'yes'){
        console.log("Are you serious? I swear what you must stop this!!");
    } else {
        console.log("Oh!! Good on you!!");
    }
        break;

default:
    console.log("What else?");

}

T^T...


#10

@magastory,

Have a close look at

business_class

vessle


#11

It's working!!!! Really appreciate it!!!:blush: