9/9 unexpected keyword 'else'


#1

I decided to make my own game. I made it to be a choose your own adventure game, but while making #1 A #2 C through #1 A #2 C #3 C, I tested it and it said, "SyntaxError: Unexpected keyword 'else'". Please help me find my mistake so I can continue making my game!
Here is the code:

    var P1 = prompt("What is your name?")
    {
        var P1answer = confirm(P1 + "... That is a cool name.");
var Path = prompt("Where are you? A.) At home B.) At the park C.) At a friend's house   Only write A, B, or C. Any other answer will not be accepted.")

/*__________________________________________________________________
#1 A
__________________________________________________________________*/
if (Path === "A")
{
var Path2 = prompt("What are you doing at home? A.) Relaxing B.) Playing a game C.) Eating dinner Again, only write A, B, or C. Any other answer will not be accepted.")
/*__________________________________________________________________
#1 A #2 A
__________________________________________________________________*/
if (Path2 === "A")
{
var Path3 = prompt("How are you relaxing? A.) Reading a book B.) Watching TV C.) Sitting down Again, only write A, B, or C. Any other answer will not be accepted.")
/*__________________________________________________________________
#1 A #2 A #3 A
__________________________________________________________________*/
if (Path3 === "A")
{
var Path4 = prompt("What kind of book are you reading? A.) Fiction B.) Non-Fiction C.) More options Again, only write A, B, or C. Any other answer will not be accepted.")
}
/*_________________________________________________________________
#1 A #2 A #3 B
_________________________________________________________________*/
else if (Path3 === "B")
{
var Path4 = prompt("What kind of show are you watching? A.) Cartoons B.) Cooking show C.) More options Again, only write A, B, or C. Any other answer will not be accepted.")
}
/*_________________________________________________________________
#1 A #2 A #3 C
_________________________________________________________________*/
else if (Path3 === "C")
{
var Path4 = prompt("What are you sitting on? A.) Regular Chair B.) Couch/Bed C.) Beanbag Chair/ Cushioned Chair Again, only write A, B, or C. Any other answer will not be accepted.")
}
}
/*__________________________________________________________________
#1 A #2 B
__________________________________________________________________*/
else if (Path2 === "B")
{
var Path3 = prompt("What kind of game are you playing? A.) Board Game B.) Card Game C.) Electronic Game Again, only write A, B, or C. Any other answer will not be accepted.")
/*_________________________________________________________________
#1 A #2 B #3 A
_________________________________________________________________*/
else if (Path3 === "A")
{
var Path4 = prompt("What board game are you playing? A.) Monopoly B.) Shoots & Ladders C.) Clue Again, only write A, B, or C. Any other answer will not be accepted.")
}
/*_________________________________________________________________
#1 A #2 B #3 B
_________________________________________________________________*/
else if (Path3 === "B")
{
var Path4 = prompt("What card game are you playing? A.) Pokemon B.) Uno C.) Go fish Again, only write A, B, or C. Any other answer will not be accepted.")
}
/*_________________________________________________________________
#1 A #2 B #3 C
_________________________________________________________________*/
else if (Path3 === "C")
{
var Path4 = prompt("What elctronic are you playing on? A.) Computer/Laptop B.) Handheld Device C.) XBox/Wii/PlayStation Again, only write A, B, or C. Any other answer will not be accepted.")
}
}
/*_________________________________________________________________
#1 A #2 C
_________________________________________________________________*/
else if (Path2 === "C")
{
var Path3 = prompt("What are you eating for dinner? A.) Takeout/Delivery B.) Feast C.) Homemade food Again, only write A, B, or C. Any other answer will not be accepted.")
/*_________________________________________________________________
#1 A #2 C #3 A
_________________________________________________________________*/
else if (Path3 === "A")
{
var Path4 = prompt("Out of 10, how good is the food?")
}
/*_________________________________________________________________
#1 A #2 C #3 B
_________________________________________________________________*/
else if (Path3 === "B")
{
var Path4 = prompt("Out of 10, how good is the food?")
}
/*_________________________________________________________________
#1 A #2 C #3 C
_________________________________________________________________*/
else if (Path3 === "C")
{
var Path4 = prompt("Out of 10, how good is the food?")
if (Path4 <= 3)
{
restaurant = prompt("Where would you rather be eating dinner at? Name a restaurant.")
}
else if (Path4 <=4 && Path4 >= 7)
{
restaurant = prompt("Where would you rather be eating dinner at? Name a restaurant.")
}
else if (Path4 <= 8)
{
restaurant = prompt("I know your dinner is tasty, but if you could choose, where would you rather be eating dinner at? Name a restaurant.")
}
confirm("Now, I have been asking many questions, and you have been answering them, but what you don't know, is I am actually a unicorn. Noww what I am going to do, is take you to " + restaurant + ".")
}
}
/*_________________________________________________________________
#1 B
_________________________________________________________________*/
else if (Path === "B")
{
var Path2 = prompt("What are you doing at the park? A.) Swinging on the swings B.) Playing on the playground C.) Sitting there Again, only write A, B, or C. Any other answer will not be accepted.")
/*_________________________________________________________________
#1 B #2 A
_________________________________________________________________*/
if (Path2 === "A")
{
var Path3 = prompt("That is all for now")
}
/*_________________________________________________________________
#1 B #2 B
_________________________________________________________________*/
else if (Path2 === "B")
{
var Path3 = prompt("That is all for now")
}
/*_________________________________________________________________
#1 B #2 C
_________________________________________________________________*/
else if (Path2 === "C")
{
var Path3 = prompt("That is all for now")
}
}
/*_________________________________________________________________
#1 C
_________________________________________________________________*/
else if (Path === "C")
{
var friend = prompt("What is your friend's name?")
var Path2 = prompt("What are you doing at " + friend + "'s house? A.) Playing a game B.) Doing homework C.) Swimming/Sport Again, only write A, B, or C. Any other answer will not be accepted.")
/*_________________________________________________________________
#1 C #2 A
_________________________________________________________________*/
if (Path2 === "A")
{
var Path3 = prompt("That is all for now")
}
/*_________________________________________________________________
#1 C #2 B
_________________________________________________________________*/
else if (Path2 === "B")
{
var Path3 = prompt("That is all for now")
}
/*_________________________________________________________________
#1 C #2 C
_________________________________________________________________*/
else if (Path2 === "C")
{
var Path3 = prompt("That is all for now")
}
}
}
}


#2

Probably you missed a }.


#3

I checked but I will check again


#4

I didn't miss any... I can't figure it out


#5

I don't see the error now, but maybe you should rewrite the game using switch instead of if/else (if you know how to use it). It is an unclosed if/else or a not needed else somewhere.


#6

Could you perhaps show me how switch is used?


#7
switch(variable) {
    case 0:
        // Anything inside the case will run if variable == 0. The break is needed in every case so you don't run other cases. 0 can be a value of whatever type you like: int, string, Object, etc.
        break;
    default:
        // This is identical to "case", except that will work if the variable doesn't equals anyone of the other values before.
        break;
}

#8

How would it work for

else if (Path3 === "C")
{
var Path4 = prompt("Out of 10, how good is the food?")
if (Path4 <= 3)
{
restaurant = prompt("Where would you rather be eating dinner at? Name a restaurant.")
}
else if (Path4 <=4 && Path4 >= 7)
{
restaurant = prompt("Where would you rather be eating dinner at? Name a restaurant.")
}
else if (Path4 <= 8)
{
restaurant = prompt("I know your dinner is tasty, but if you could choose, where would you rather be eating dinner at? Name a restaurant.")
}
confirm("Now, I have been asking many questions, and you have been answering them, but what you don't know, is I am actually a unicorn. Noww what I am going to do, is take you to " + restaurant + ".")
}
}


#9

Sorry, switch only handles equals, not other operators (as far as I know). So all inside the if remains equal. The if statement should be a case with value "C".


#10