Logical operators! Please help!


#1



Please help!

I am on lesson 5 of "code your own adventure 2!"


when I try to save and submit, it says "SyntaxError: Parser error" i don't see any thing wrong please help!!

here is my code:


var answer = prompt("What are you?(warrior, farmer or hunter)").toUpperCase();

var user = (answer);

switch(answer) {
    case 'WARRIOR':
        var c1 = prompt("are you brave?").toUpperCase();
        var c2 = prompt("are you keen?").toUpperCase();
        if (c1 === 'YES' && c2 === 'YES') {
        console.log("Welcome to battle school!");
        }else{
            console.log("Sorry, but you weren't excepted in to battle school!")
        break;
}
}
    case 'FARMER':
        var c3 = prompt("are you diligent?").toUpperCase();
        var c4 = prompt("are you not afraid to get dirty?").toUpperCase();
        if (c3 === 'YES' || c4 === 'YES')
        console.log("you will be apprenticed by a farmer!");
        }else{
            console.log("sorry, but we can't have a lowsy farmer!");
        break;
}
}
    case 'HUNTER':
        var c5 = prompt("can you easily go unseen?").toUpperCase();
        var c6 = prompt("can you expertly shoot a bow?").toUpperCase();
        if (c5 === 'YES' && c6 === 'YES') {
        console.log("You will make a great hunter!");
        }else\if (c5 === 'YES' && c6 === 'NO') {
            console.log("sorry, but we can't have a hunter that can't shoot a bow!");
        }else{
            console.log("sorry but we can't have a loud hunter!");
        };
        break;
}
}
        
    default:
        console.log("sorry but we dont have any " + answer + "ing  available!");
}
};


#2

Why are there two braces here? That essentially closes the switch loop! Im sure your smarter than that @jallu2.0!


#3

@amanuel2
oh my gosh, i did not see that! but now it says "SyntaxError: Unexpected keyword 'else'"! what does that mean?


#4

After you fix the problem i stated before you have this code:

var answer = prompt("What are you?(warrior, farmer or hunter)").toUpperCase();

var user = (answer);

switch(answer) {
    case 'WARRIOR':
        var c1 = prompt("are you brave?").toUpperCase();
        var c2 = prompt("are you keen?").toUpperCase();
        if (c1 === 'YES' && c2 === 'YES') {
        console.log("Welcome to battle school!");
        }else{
            console.log("Sorry, but you weren't excepted in to battle school!")
        break;
}
    case 'FARMER':
        var c3 = prompt("are you diligent?").toUpperCase();
        var c4 = prompt("are you not afraid to get dirty?").toUpperCase();
        if (c3 === 'YES' || c4 === 'YES')
        console.log("you will be apprenticed by a farmer!");
        }else{
            console.log("sorry, but we can't have a lowsy farmer!");
        break;
}
}
    case 'HUNTER':
        var c5 = prompt("can you easily go unseen?").toUpperCase();
        var c6 = prompt("can you expertly shoot a bow?").toUpperCase();
        if (c5 === 'YES' && c6 === 'YES') {
        console.log("You will make a great hunter!");
        }else\if (c5 === 'YES' && c6 === 'NO') {
            console.log("sorry, but we can't have a hunter that can't shoot a bow!");
        }else{
            console.log("sorry but we can't have a loud hunter!");
        };
        break;
}
}
        
    default:
        console.log("sorry but we dont have any " + answer + "ing  available!");
}
};

First Problem is here:

if your going to end a if statement, you have to start it...

Second of all @jallu2.0 what is with the else/if ?? its else if...


#5

@amanuel2
ok, does a "case" statement need to be closed with a }?