Code your own adventure2


#1

please help debugging??

var userAnswer = prompt(“Hi, do you want to play with doraemon, , nobita, or suzuka?”).toUpperCase();

switch(userAnswer){
case ‘doraemon’:
var gadgets= prompt(“are you interested in using gadgets”).toUpperCase();
var playfair= prompt(“or you don’t want help”).toUpperCase();
if (gadgets===‘yes’&& playfair===‘yes’) {
console.log(“great, let’s start”);
} else {
console.log(“good choice”);
}
break;

case 'nobita':
    var dumbo= prompt("do you want some help").toUpperCase();
    var lucky= prompt("do you think he will manage,but needs some points").toUpperCase();
    if (dumbo==='yes'&& lucky==='yes') {
        console.log("he will definitely win");
    } else {
        console.log("Sorry, choose your player again");
    }
    break;
    
case 'suzuka':
    var pretty= prompt("do you think she is pretty?").toUpperCase();
    var smarty= prompt("do you think she can win?").toUpperCase();
    if (pretty==='yes'||smarty==='yes') {
        console.log("very good choice);
    } else {
        console.log("you can change player");
    }
    break;
    

    
default:
    console.log("Sorry, you should choose between nobita, suzuka, and doraemon only);

}


#2
  1. Use .toLowerCase() method because your cases have lower case values.
  2. You need to close string values:
...
console.log("very good choice); // missed " after word choice
...

console.log("Sorry, you should choose between nobita, suzuka, and doraemon only); // same thing after word only
  1. You need to close switch statement using }.

#3

thaks alot,
It worked. But can’t we use freely .toLoweCase and .toUpperCase options.


#4

We can use both methods. All JavaScript identifiers are case sensitive. So when we are using .toLowerCase() method case must be:

case 'doraemon'

and with .toUpperCase() method:

case 'DORAEMON'

These methods you can use with string:

 'doraemon'.toUpperCase();

or with string variables:

var str1 = 'doraemon';
var str2 = str1 .toUpperCase();

So .toLowerCase() and .toUpperCase() are often using with prompt() to avoid mistakes.


#5

A post was split to a new topic: Make sure to use a break statement with each case!


#6