Logical operators


#1

ar user =prompt("who are you?").toUpperCase();
switch(user) {
case'aaa':
console.log("qwerty");
break;
case'zzz':
console.log("asdfgh");
break;
case'sss':
console.log("zxcvbn");
break;
default:
console.log("asderfg");
break;
}
what should I do in this ?


#2

Hello Jyotishkaaich, I'm not sure I'm understanding your problem. Are you asking what you should output? Or are you asking what that code is?


#3

will you explain me more about the output


#4

switch syntax:

switch(expression) {
    case n:
        code block
        break;
    case n:
        code block
        break;
    default:
        code block
}

So, how it works:
1. The switch expression is evaluated once.
2. The value of the expression is compared with the values of each case.
3. If there is a match, the associated block of code is executed.

In your case expression is the user answer (variable user). But you add toUpperCase() method, so you need to consider it in cases:

switch(user) {
    case 'AAA':
    ...
}

or use toLowerCase() method.
So, if user === "aaa" output will be "qwerty".


#5

in this how will I use || and &&


#6

var user =prompt("who are you?").toUpperCase();
switch(user) {
case'aaa':
if(user || "aaa") {
console.log("qwerty");
}
else {
console.log("ZAQSXDEDC");
};

break;
case'zzz':
if(use && "zzz") {
    console.log("asdfgh");
}
else{
    console.log("csfrgs");
}
break;
case'sss':
    console.log("zxcvbn");
break;
default:
    console.log("asderfg");
break;

}
can you explain me about this topic?


#7

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