Logical operators


#1

what's wrong with my code.Its only executing default case.M not getting proper output. Please help. Here's my code:-
var user=prompt("What is your name?").toLowerCase();
var name=0;
var surname=0;
switch(user){
case 0:
if(name===rutuja && surname===patil)
{
console.log("Aah! I got your name and I like it:)");
}else{
console.log("Oh! You got married");
}
break;
case 1:
if(name===kushal || surname===pusadkar)
{
console.log("You must be rutuja's husband");
}else{
console.log("Sorry if i bother you");
}
break;
default:
console.log("Sorry!!I don't know you.");
}


#2

Have a look at the cases in your switch statement. They are the values that are getting checked for in the user var (the value you enter into the prompt). You could change it to something like this maybe:

var user=prompt("What is your name?").toLowerCase();

switch(user){
    case "rutuja":
        console.log("Aah! I got your name and I like it:)");
        break;
    case "kushal":
        console.log("You must be rutuja's husband");
        break;
    default:
        console.log("Sorry!!I don't know you.");
    }

#3

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