What's wrong with my code!?


#1

var user=prompt("On your quest there is one more challenge,to cross over the bridge of death.But there is the bridge keeper.Will you answer his question,try to pay him money or run.").toLowerCase() ;
switch (user) {
case "answer question " :
var brave=prompt("Are you brave ( yes or no )?").toLowerCase();
var smart=prompt("Are you smart ( yes or no )?").toLowerCase();
if (brave==="yes" || smart==="yes") {
console.log("If you are brave or smart you can pass");}
else {"If you are not brave or smart then you are cursed into the gorge of eternal fire.YOU LOSE!");
}
break;
case "pay him " :
var money=prompt ("Do you have any money!?").toLowerCase();
var dinars=prompt("Is it dinars?").toLowerCase();
if (money ===" yes" && dinars === "yes") {
console.log("OK then.You can pass, but don`t say to anyone or you WILL burn into the gorge of eternal fire!!");
}
else {
console.log("Well then you are cursed into the gorge of eternal fire.YOU LOSE!);
}
break;
case "run " :
console.log ("Coward!!");
break;
default :
console.log("I didn't understand your choice. Hit correct answer and try again, this time picking answer question, pay him or run!");
};


#2

Your else statements should be console.log();.


#3

Oh ,thanks I didn't see that,but again it shows "Syntax Error..."


#4

Hmm... I can't see any mistakes. Try to refresh the page.


#5

dear Burdush,

i was strugling with my code. then looked at your question and decided to copy paste it instead of my code, then debugged it to make it work.
now it works. here is a copy. sorry i did not keep log of the changes i made. but see line by line and try pick up the bits i changed.

var user=prompt("On your quest there is one more challenge,to cross over the bridge of death.But there is the bridge keeper.Will you ANSWER his question,try to PAY him money or RUN.").toLowerCase() ;
switch (user) {
case 'answer' :
var brave=prompt("Are you brave ( yes or no )?").toLowerCase();
var smart=prompt("Are you smart").toLowerCase();
if (brave==='yes' || smart==='yes') {
console.log("If you are brave or smart you can pass")
}
else {console.log("If you are not brave or smart then you are cursed into the gorge of eternal fire.YOU LOSE!")};
break;

case 'pay':
var money = prompt("Do you have any money?").toLowerCase();
var dinars = prompt("Is it dinars?").toLowerCase();
if (money === 'yes' && dinars === 'yes') {
console.log("OK then.You can pass, but don`t say to anyone or you WILL burn into the gorge of eternal fire!!");
}
else {
console.log("Well then you are cursed into the gorge of eternal fire.YOU LOSE!")
}

break;

case 'run':
console.log("Coward!!");
break;

default :
console.log("I didn't understand your choice. Hit correct answer and try again, this time picking answer question, pay him or run!");
};


#6

Thanks byterunner and you scriptdolphin I figured it out .Beside my two mistakes that I didn't see :
console.log("Well then you are cursed into the gorge of eternal fire.YOU LOSE!);
---(" on the end)---
and
else {"If you are not brave or smart then you are cursed into the gorge of eternal fire. YOU LOSE!");}
---console.log inside else statement---

what I didn't know was :

case 'pay him' :
---instead of---
case"pay him" :

and

if (money ==='yes' && dinars === 'yes')
---instead of---
if (money ==="yes" && dinars === "yes")