Logical Operators: unexpected token else + other problems?


#1

I made my code a bit more complex than I had to because I was feeling creative. It keeps giving me a
SyntaxError: unexpected token else.

I don't understand what I am doing wrong, can someone please look over my code and tell me what mistakes I'm making? I'm not sure if I'm not supposed to nest the if/else statements like that or what..

Anyways, here's my code. I apologize for the length. I tried getting rid of the first switch and changing the prompt to a simple : Do you want to EXPLORE, WAIT, or BLOWSHITUP? But I was still getting the unexpected token else error so I'm guessing its not accepting it because there is something wrong with my if/else statements. Someone help? Please?


var user = prompt("You wake up laying on a concrete floor. You don't know where you are and the air smells old and musty. It's cold. You hear a female voice to your left. '. . .Well, good job dumbass! We're stuck in this place now!' You have no idea who this woman is. 'Who are you to go running in front of my bike, like a lunatic, being chased by those guys with helmets?! Who were they? Where the fuck are we?! I get knocked out and we wake up in here.' You see the black haired girl kick a wall, then sit down by you. 'Who are you anyways? What's your name?'...You can't remember much about yourself, but your name comes to the surface..").toUpperCase();

switch(user) {
    case 'ALICE':
        console.log("That's a really nice name, hey, you know what, that's my name too! I'm Alice, Alice Rose, nice to meet you ^-^")
break;

        
    case 'JENNA':
        console.log("'That's a really nice name.' Alrighty then... Nice to meetcha! I'm Alice.'");
        break;
    
    default:
        console.log("...the woman stares at you. 'Hmm, that sounds familiar.. Well, okay. Nice to meetcha. I'm Alice.'");
}



var Q1 = prompt("Ok, well we should probably find some way out of here. What do you want to do? EXPLORE, WAIT, or BLOWSHITUP?").toUpperCase();

switch(Q1) {
    case 'EXPLORE':
        console.log("Okay, we'll explore then.");
        var myVision = prompt("It's really dark in here.. Can you see well in the dark..?");
        var myFlashlight = prompt("You don't happen to have a flashlight.. do you..?");
        
        if (myVison === "yes" || myFlashlight === "yes") {
            console.log("Alright! Let's go!");
        }
        
        else {
            console.log("Hmm.. too bad. If we can't see to explore, I guess we're just stuck here.");
        }
        
    break;
    
    case 'EXPLORE':
        console.log("Okay, we'll wait then. Maybe a guard will come by and we can attack him or steal his keys somehow.")
        var luck = prompt("You feeling lucky at all?");
        var fight = prompt("Any good at fighting barehanded..?");
        
        if (luck === "yes" && fight === "yes") {
            console.log("You hear footsteaps nearby. 'Here he comes!! LETS TAKE HIM DOWN!' As the door opens you tackle the guard and Alice hits him in the head, hard. He is knocked unconcious and you steal the keys and escape the cell.")
        else {
            console.log("GEEZUS! Why do I have to get stuck with such a useless person. Do you have smarts at least..? My god..");
        }
        
    break;
    
    case 'BLOWSHITUP': 
        console.log("Aight. Lets do it.")
        var bombs = prompt("You do have some sort of explosives, right? And something to light them, right?")
        
        if (bombs === "yes") {
            console.log("You light the explosives. ...... . .  . BOOOOOM!!! You blow yourself up and Alice. NICE GOING! DONT PLAY WITH FIRE OR EXPLOSIVES KIDS");
            
        } else {
            console.log("Awh... I guess we can just wait here until we're rescued by someone then..");
        }
        
    break;
    
    default: ("Please input EXPLORE, WAIT, or BLOWSHITUP")

#2

There were quite a few errors in your code. I fixed them. Not sure if I found all the errors. The once I fixed I marked with a comment.

var user = prompt("You wake up laying on a concrete floor. You don't know where you are and the air smells old and musty. It's cold. You hear a female voice to your left. '. . .Well, good job dumbass! We're stuck in this place now!' You have no idea who this woman is. 'Who are you to go running in front of my bike, like a lunatic, being chased by those guys with helmets?! Who were they? Where the fuck are we?! I get knocked out and we wake up in here.' You see the black haired girl kick a wall, then sit down by you. 'Who are you anyways? What's your name?'...You can't remember much about yourself, but your name comes to the surface..").toUpperCase();

switch(user) {
    case 'ALICE':
        console.log("That's a really nice name, hey, you know what, that's my name too! I'm Alice, Alice Rose, nice to meet you ^-^")
break;

        
    case 'JENNA':
        console.log("'That's a really nice name.' Alrighty then... Nice to meetcha! I'm Alice.'");
        break;
    
    default:
        console.log("...the woman stares at you. 'Hmm, that sounds familiar.. Well, okay. Nice to meetcha. I'm Alice.'");
}



var Q1 = prompt("Ok, well we should probably find some way out of here. What do you want to do? EXPLORE, WAIT, or BLOWSHITUP?").toUpperCase();

switch(Q1) {
    case 'EXPLORE':
        console.log("Okay, we'll explore then.");
        var myVision = prompt("It's really dark in here.. Can you see well in the dark..?");
        var myFlashlight = prompt("You don't happen to have a flashlight.. do you..?");
        
        if (myVision === "yes" || myFlashlight === "yes") { // myVison ->myVision
            console.log("Alright! Let's go!");
        }
        
        else {
            console.log("Hmm.. too bad. If we can't see to explore, I guess we're just stuck here.");
        }
        
    break;
    
    case 'WAIT': // had case "EXPLORE" twice, change this to "WAIT"
        console.log("Okay, we'll wait then. Maybe a guard will come by and we can attack him or steal his keys somehow.")
        var luck = prompt("You feeling lucky at all?");
        var fight = prompt("Any good at fighting barehanded..?");
        
        if (luck === "yes" && fight === "yes") {
            console.log("You hear footsteaps nearby. 'Here he comes!! LETS TAKE HIM DOWN!' As the door opens you tackle the guard and Alice hits him in the head, hard. He is knocked unconcious and you steal the keys and escape the cell.")
        } //added
        else {
            console.log("GEEZUS! Why do I have to get stuck with such a useless person. Do you have smarts at least..? My god..");
        }
        
    break;
    
    case 'BLOWSHITUP': 
        console.log("Aight. Lets do it.")
        var bombs = prompt("You do have some sort of explosives, right? And something to light them, right?")
        
        if (bombs === "yes") {
            console.log("You light the explosives. ...... . .  . BOOOOOM!!! You blow yourself up and Alice. NICE GOING! DONT PLAY WITH FIRE OR EXPLOSIVES KIDS");
            
        } else {
            console.log("Awh... I guess we can just wait here until we're rescued by someone then..");
        }
        
    break;
    
    default: 
     console.log("Please input EXPLORE, WAIT, or BLOWSHITUP"); //incomplete, added console.log
}//added

#3

Ok. Thank you so much!!
I really appreciate you taking the time to go over all of my code.
It works now :smile: