Switch in a switch possible?


#1


I tried making a switch inside a case of a switch this didnt work and im not sure if its possible or if i did something wrong, however this is the error im receiving. Also in a case name how am i supposed to use the ' as in it's or your's, right now i left out the '.

SyntaxError: expected expression, got keyword 'case

I then replaced the switch(userA) with a if/else and this worked out fine but i would like to know how the coding should be if i did use the switch(userA).

PS: dint mind the prompts and console.log as i had to think of some answers and questions:)


var user = prompt("What is up with all this coding?").toUpperCase();

switch(user) {
    case 'DONT KNOW':
        console.log("Yea me neither");
        a1 = true;
        a2 = true;
        if(a1 && a2){
            console.log("There is just so much of it");
        } 
        break;
    case 'ITS FUN':
        console.log("IKR");
        a3 = true;
        a4 = false;
        if(a3 || a4){
            console.log("There is so much to do");
        }
        break;
    case 'I HATE IT':
        console.log("That sucks");
        var userA = prompt("But why?").toUpperCase();
        Switch(userA);{
            case 'ITS JUST SO MUCH' :
                console.log("It is prolly just nothing for you then");
                break;
            case 'IM NOT GOOD AT IT' :
                console.log("Practise more!");
                break;
            default :
                console.log("Well yea its not for everyone!");
        }
        break;
    default :
        console.log("Oke");
};


#2

@nattebadmuts

Theoretically (though I've never tried it), it is possible to place a switch statement inside another switch statement. However, for the purposes of this lesson, please use an if statement.

In regards to your issue, try removing the semicolon after Switch(userA) and make it lowercase s in "switch"...

switch(userA); { ...


#3

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