My code runs only the 'default' statement!....Please Help ASAP!


#1


var user = prompt("What's your name?").toUpperCase();

switch(user) {
    case 'Azeem':
        var name1 = prompt("You're still the same person!");
            if (name1 == 'Azeem' && 'Kazeem') {
                console.log("I'm ur friend.")
            }else {"I don't know you!"};
        console.log("I know u!");
        break;
        
    case 'Buck':
        var name2 = prompt("That's me!");
            if (name2 == 'Buck' || 'Kamari') {
                console.log("All me!")
            }else {"Not Clement Oboh!!!"};
        console.log("My nickname!");
        break;
        
    case 'Huzaifa':
        var name3 = prompt("Huzy Pankus Chanklinkon...");
            if (name3 == !"Huzaifa" || !"Pankus") {
                console.log("You're not Chanklinkon!")
            }else {"Huzy my man!"};
        console.log("The NDA man!!");
        break;
    
    default: console.log("I don't know you!");
};


#2

Hi this line

var user = prompt("What's your name?").toUpperCase();

remove this .toUpperCase(); because your case are both uppercase and downcase..And remenber to write Azeem or Buck


#3

Thanks. I thought '.toUpperCase()' was there to turn every response to upper case.


#4

YEs it does that but you case are uppercase and downcase

case 'Azeem':

so if you type Azeem the .toUpperCase(); will change it to

'AZEEM'

and it will print the default case because it won't match with any case


#5

Okay I understand it now. Thanks a bunch!


#6

Okay. My if statements don't work...it just runs the case and ignores the if statements.


#7

why not , what does it print?


#8

When i type in Azeem Kazeem, it says > I don't know you!


#9

Becasue you made it with**And**

if (name1 == 'Azeem' && 'Kazeem')

or you create two promp one for Azeem another for Kazeem or you pu it like that

if (name1 == 'Azeem Kazeem')

#10

i still don't understand. Basically all if statements don't work


#11

I run you code and it work.. Let's says you type Azeem

 var name1 = prompt("You're still the same person!");
            if (name1 == 'Azeem' && 'Kazeem') {

then the name1 prompt you CAN'T TYPE Azeem Kazeem because your if statenemt check for the name Azeem and Kazeem and not for Azeem Kazeem


#12

Yes you're right. My bad..i first typed in names in the if statements before the case


#13

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