Code your own adventure 2


#1

Hi guys.
I kind of tried to go a little bit more in depth with this adventure game. Now my code is coming up with up with illegal token else syntax. I was just wondering if someone could have a quick read through to see where I have messed up.
Cheers.

var user=prompt("Are you ready for this?","YES,NO,MAYBE").toUpperCase();
switch(user){
    case'YES':
        console.log("Good, it seems like you are the one we have been waiting for.");
        prompt("What is your name child?");
        break;
    case'NO':
        console.log("We thought you were the one. We appologise for any inconvinience, please join the other commoners and await your death.");
        console.log("GAME OVER");
        break;
    case'MAYBE':
        console.log("Ah, lack of self confidence ey? Always happens with the new ones. Well you beter get ready, we leave at first dawn.");
        break;
    default:
        console.log("I do not understand your response. How does that answer my question?");
};
if (user===YES){
    console.log("The elder of your village comes and greets you")};
    var sword=prompt("Did you bring your Fathers sword? The one of the legends?","YES,NO,MAYBE","YES,NO,MAYBE").toUpperCase();
    var armour=prompt("Or your Mothers armour? The mythical armour of Mucro?","YES,NO,MAYBE").toUpperCase();
    if(sword===yes&&armour===yes){
        console.log("Good. We can continue")};
    else if(sword===yes||armour===yes){
        console.log("You brought one with out the other? Are you stupid? Go and get the other")};
    else{
        console.log("The elder facepalms. 'This is going to be a long trip'")};

else if(user===MAYBE){
    console.log("You had better find your courage fast child")};
    var sword=prompt("Did you bring your Fathers sword? The one of the legends?","YES,NO,MAYBE","YES,NO,MAYBE").toUpperCase();
    var armour=prompt("Or your Mothers armour? The mythical armour of Mucro?","YES,NO,MAYBE").toUpperCase();
    if(sword===yes&&armour===yes){
        console.log("Good. We can continue")};
    else if(sword===yes||armour===yes){
        console.log("You brought one with out the other? Are you stupid? Go and get the other")};
    else{
        console.log("The elder facepalms. 'This is going to be a long trip'")};   
else {
    console.log("GAME OVER")};

#2

ok, remember that you cannot have a semi-colon " ; " after your closing brackets " } " when the closing bracket is linked to an if statement. (See quote). You have this for every if statement and that will trip you up every time. It will always close the "If-Chain" This is complicated but for now just assume that you should never do this.

What you were trying to do was close the console.log statement, and to do that it would have to look like this:

 else{
        console.log("The elder facepalms. 'This is going to be a long trip'") ; }
                                                                              ^
                               //Put semi-colon on the inside of the closing bracket

Do this for all of your if statements and see if that clears it up.

Side Note:

To format your code like I have done, put it in between 2 sets of three back ticks, like this:

```
<Put your code Here!>
```

and then it will make your code go from looking like this:

console.log("Hello World");

to this:

console.log("Hello World");