Error message illegal return statement


#1



the error message shown is illegal return statement:
what have i done wrong? help needed

var user = prompt("Do you wanna fight, run or pay?", "Type your answer here").toUpperCase();
switch(user){
    case 'FIGHT':
        return "u are courageous";
        break;
    case 'RUN':
        return "thats okay";
        break;
    case 'PAY'
    consoel.log("how much do u wanna pay?");
    break;
    default:
    console.log("u didnt choose correctly");
}


#2

Hi this part you wrote consoel.log() instead of console.log()


#3

also you're missing the ':' for case 'PAY'


#4

thanks!. i corrected the two mistakes pointed out. although the error message shown is still the same "illegal return statement

var user = prompt("Do you wanna fight, run or pay?", "Type your answer here").toUpperCase();
switch(user){
case 'FIGHT':
return "u are courageous";
break;
case 'RUN':
return "thats okay";
break;
case 'PAY':
console.log("how much do u wanna pay?");
break;
default:
console.log("u didnt choose correctly");
}


#5

Just use this code below, let me know if it works. Then I will explain why and how it works.

Cheers

var isEven = function(number) {
if (number%2 === 0) {
return true;
}else {
return false;
}
};


#6

oops, sorry. Wrong code. Replying a different question


#7

try this:

var user = prompt("Do you wanna fight, run or pay?, Type your answer here").toUpperCase();
switch (user) {
case 'FIGHT':
return "u are courageous";
break;
case 'RUN':
return "thats okay";
break;
case 'PAY':
return ("how much do u wanna pay?");
break;
default:
return ("u didnt choose correctly");
}


#8

@systemplayer80880 I tried the above code. it still shows the same error


#9

You should change all your return statement by the console.log()


#10

yes it works now by changing return statements to console.log. Thanks!
Any reason why return statements wont work??


#11

the return statemnt inside the switch statemnt work without break statement you can read this


#12

@wizmarco thank you.