Code Your Own Adventure 2. Help please!


var user = prompt("ur standing at a crossroad.Choose right, left or straight to get home").toUpperCase();

switch(user) {
case 'right':
var fightingBandit = prompt("will u fight the bandit to get home - yes/no").toUpperCase();
var payingBandit = prompt("will u pay the bandit to get home - yes/no").toUpperCase();
if(fightingBandit === 'yes' && payingBandit === 'yes') {
console.log("u gotta fight n pay the bandit to continue the journey");
}else {
console.log("the bandit'll rob u & stop u from continuing ur journey");

case 'left':
var helpingBeggar = prompt("will u help the beggar n let him show u the way home - yes/no").toUpperCase();
var meetingCompanions = prompt("will u be with other companions - yes/no").toUpperCase();
if(helpingBeggar === 'yes' || meetingCompanions === 'yes') {
console.log("ur a good man to either help the beggar or be with other companions");
}else {
console.log("ur an unkind, lonely person");

case 'straight':
var findingAMap = prompt("will u use a map to get home - yes/no").toUpperCase();
var gettingDirections = prompt("will u listen to people's instructions for direction - yes/no").toUpperCase();
if(findingAMap === 'yes' || gettingDirections === 'yes') {
console.log("a map or getting directions sound like a good plan");
}else {
console.log("you'll be likely to get lost");

console.log("ur not taking any chance, so u dont wanna go home?");

Those are my pieces of code. I passed this exercise but there's something i haven't figured out. No matter what i do, the result will always only print out the default part and not the others. I might have made some mistake along the way but i dont know what. Could someone help me point out the wrong parts plz? Thank u very much !!!!


I don't know why each and every user makes exactly this same mistake (maybe the course should be revised..). Anyway, in your program you convert the user input to UPPER CASE by using the method .toUpperCase();. This means whether the user enters "left", "Left", "leFt", "LEFt" or any other combination, it is converted to "LEFT" (all letters are converted to upper case by the method). But this means that the user's input, which is always uppercase, can NEVER MATCH a lower-case case name.
-> LEFT != left

So either you have to adjust your cases names and make them upper case. Or you have to drop the conversion.


because you are using the toUpperCase(), then your case has to be in uppercase as well