Lesson 5 (Logical Operators) - Code Your Own Adventure ... Help with my code, please?


#1

Here is my code. I'm receiving the following error message: "SyntaxError: expected expression, got keyword 'else'".
I can't figure out what I've done wrong. Please help?

Edited code from first posting as shown below, but still getting the same error message

var answer = prompt("Do you choose the path to the right, the left, or straight?").toLowerCase();
var user = answer;
var right = true;
var left = true;
var straight = true;

switch (answer) {
case 'right':
if (right || left) {
console.log("The " + answer + " path looks clear!");
break;
}
case 'left':
else if (right && left) {
console.log("You can't go two ways at once!");
break;
}
case 'straight':
else {
console.log("Yep, " + answer + " is always a good bet.");
break;
}
default:
console.log("I don't understand your selection. Try again.");
}


#2

@melorona,
a google search
== the Book ==
javascript switch() site:developer.mozilla.org
= https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/switch
javascript if statement site:developer.mozilla.org
= https://developer.mozilla.org/nl/docs/Web/JavaScript/Guide/Control_flow_and_error_handling

You ar badly mingling the 2 statement-types...!!!


#3

@leonhard_wettengmx_n... Ugh thank you. I felt like it was completely wrong. Back to the drawing board. Thank you for the links and for taking the time to respond! :blush: