4.Switch


#1


var user1 = prompt("what you want to play").toUpperCase();

switch(user1){
    case 'bat':
        console.log("do you want to play cricket");
        break;
    case 'tennis bat':
        console.log("do you want to play tennis");
        break;
    case 'chess board':
        console.log("do you like to play chess");
        break;
    default:
        console.log("hi");
                
}


my code is working but whatever i choose in the case the result comes only the default value "Hi".
What is the problem in it?


#2

var user1 = prompt("what you want to play").toUpperCase();

you take the input value as UpperCase

but

case 'bat':

for checking you are using mixcase


#3

no whatever uppercase and lowercase i tried all things but the result is same


#4

If you use toUpperCase() for user1 then for checking write

case 'BAT':

you have to change all the cases
and for toLowerCase()

case 'bat':

If problem persists,post update version of your code.


#5

Now it's working properly... thanks for your solution
:slight_smile:


#6

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.