Code your Adventure: 2


I believe that I have coded it correctly however it keeps switching to the default Switch. Any advice

var user = prompt("Who are you?").toUpperCase();

switch(user) {
    case 'Knight':
        var strong = prompt("Are you Strong (YES or NO) ?").toUpperCase();
        var smart = prompt("Are you Smart?").toUpperCase();
        if(strong === 'YES' || smart === 'YES') {
            console.log("You only need one of the two! You are qualified to be a Knight! Congratulations!");
        } else {
            console.log("You're neither strong or smart? Well, How about we make you a Peasent or a Jester");
    case 'Assasin':
        var swift = prompt("Are you Swift (YES or NO) ?").toUpperCase();
        var stealth = prompt("Are you Stealthy ?").toUpperCase();
        if(swift === 'YES' && stealth === 'YES') {
            console.log("All right! You have all it takes to be an Assasin, Congratulations!");
        } else {
            console.log("It takes both stealth and Agility to be an Assasin, Sadly you lack either");
    case 'Mage':
        var alchemy = prompt("Do you have knowledge of Alchemy (YES or NO) ?").toUpperCase();
        var hat = prompt("Do you have a Pointy hat ?").toUpperCase();
        if(alchemy === 'YES' || hat === 'YES') {
            console.log("Well, at least you are old enough to be a Mage, Congratulations!");
        } else {
            console.log("You deserve to be a Peasent!");
    console.log("Ahhh.. another Jester! Off with your head!!!");


Your user variable is set to the uppercase version of the received input. So, if we receive "knight" it becomes "KNIGHT", therefore not satisfying any of the conditions.

I suggest changing all the cases to lowercase and making your prompt .toLowerCase() instead of .toUpperCase().


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