Need some help here... Don't understand my SyntaxError


#1


https://www.codecademy.com/en/courses/javascript-beginner-en-ZA2rb/0/6?curriculum_id=506324b3a7dffd00020bf661


Every time I save my code, it keeps on saying SyntaxError : Syntax Error. I don't understand what I did wrong, please help me out guys!


if(confirm("Do you wish to launch the game?")==true) {
    confirm("You are playing Father's day adventure");
    var name = prompt("What is your name?");
    switch(name) {
        case 'Cheese':
            confirm("Nice to meet you.")
            break;
            default:
            confirm("Nice to meet you, " + name + ".");
    }
    var ask=prompt("It's Father's day, do you make a CAKE for your dad, or do you buy him a PRESENT?").toUpperCase();
    switch(ask) {
        case 'CAKE':
            var cake=prompt("Do you know how to make a cake, yes or no?").toUpperCase();
            if(cake === 'YES') {
                confirm("Good. You made the cake.")
            } else if(cake === 'NO'){
                confirm("Then Why did you choose to make a cake?!")
            } else {
                confirm("ERROR.");
            }
            
            if(cake ==='YES') {
                confirm("You put the cake into the back of your car.");
                var car = prompt("But as you got into your car, you realized that you lost your keys. Do you try to HOTWIRE your car, or do CONTINUE by foot?").toUpperCase();
                switch(car) {
                    case 'HOTWIRE':
                    var slaying2=true;
                    var youHit2=Math.floor(Math.random() *2);
                    damageThisRound2=Math.floor(Math.random()*5);
                    totalDamage2=0;
                    while (slaying2) {
                        if (youHit2) {
                            confirm("*sizzle*");
                            confirm("*sizzle*");
                            totalDamage2 += damageThisRound2;
                            if (totalDamage2 >= 4) {
                                confirm("Yes! Your car started!");
                                slaying2 = false;
                            } else {
                                youHit2 = Math.floor(Math.random() * 2);
                            }
                        } else {
                            confirm("Oh no! Your car wouldn't start!");
                            slaying2 = false;
                            confirm("So then you decided to walk. But by the time you got to your dad's house, the cake went bad, and you were late by 3 weeks!");
                        }
                    }
                    break;
                    case 'CONTINUE':
                        confirm("You walked and walked, but by the time you got to your dad's house, the cake went bad, and you were late by 3 weeks!");
                }
                if (totalDamage2 >= 4) {
                    confirm("You drove your car, but your car ran out of gas. You pull up to the gas station.")
                    confirm("You start to fill up...");
                    var i = 0;
                    for (; i < 9; i++) {
                        confirm(i + " litre(s)");
                        if(i >= 1) {
                            continue
                        } else {
                            confirm("");
                        }
                    } confirm("You paid for the gas, but someone stole your car!");
                    var thief = prompt("Do you CHASE the crazy guy, or WALK back home and mope all the way?").toUpperCase();
                    switch(thief) {
                        case 'CHASE':
                            var chase = prompt("Are you fast?").toUpperCase();
                            var chaseII = prompt("Are you a cop?").toUpperCase();
                            if(chase === 'YES'||chaseII === 'YES') {
                                confirm("Great! You started chasing the crazy guy!")
                            } else if(chase === 'YES'&&chaseII === 'YES') {
                                confirm("Whoa. You're a cop!!!")
                            } else {
                                confirm("a) you're boring. b) the guy who stole your car got away. And c), that is saddening(sry).")
                            } if(chaseII === 'YES') {
                                confirm("Since you're a cop, you called your buddies and you got a cop car, and started to chase the guy, yay!");
                            } else {
                                confirm("You started to chase the guy.");
                            }
                            break;
                            case: 'WALK':
                                confirm("You walked, moped, ate McDonalds and repeated this until you: got home, ran out of money and looked like a homeless person.");
                    }
                    if(chaseII === 'YES') {
                        confirm("You chased the guy in your cop car, and eventually you arrested the guy and you got the cake back!")
                    } else {
                        confirm("You chased him, and chased him, but he got away with the cake. Well, looks like you'll have to get dad something else :-(")
                    }
                }
            break;
            case 'PRESENT':
                confirm("You went to Moores, and decided to buy a suit for your dad.")
                var buy = prompt("But when you got to Moores, there was only one suit left. There's one more guy eyeing the suit. The clerk doesn't want a big fuss so you have to challenge the guy. Do you CHALLENGE him, or WALK away?").toUpperCase();
                switch(buy) {
                    case 'CHALLENGE':
                    var Daddy = true;
                    var youWant = Math.floor(Math.random() * 2);
                    var ThisRound = Math.floor(Math.random() * 5 + 1);
                    var Damage = 0;

                    while (Daddy) {
                        if (youWant) {
                            confirm("You hit the guy and did " + ThisRound + " damage!");
                            Damage += ThisRound;
    
                            if (Damage >= 4) {
                                confirm("You did it! You defeated the guy!");
                                Daddy = false;
                            } else {
                                youWant = Math.floor(Math.random() * 2);
                            }
                        } else {
                            confirm("No!!! You didn't do enough damage. You only did " + ThisRound + " damage!");
                            Daddy = false;
                        }
                    }
                    break;
                    case 'WALK':
                        confirm("Great. You don't have anything else to get for your dad, so you decide to make a cake, but you discover that your dad is sick and tired of cakes. Oh well, better luck next year.")
                }
                if (Damage >= 4) {
                    confirm("You march out victorious and bask in glory, so you put the suit in your car.")
                    var traffic = prompt("You drive onto the road, but there's a traffic jam! You reach into your pocket, and you find two things, a space PORTAL, and a TELEPORT. Which one do you use?").toLowerCase();
                    if (traffic === 'portal") {
                        confirm("You opened up the portal, but you didn't understand a thing about the space-time continuum, so you ended up stranded in space. Well " + name + ", you should've paid attention in astronomy class. Oh well!")
                    } else if (traffic === 'teleport') {
                        confirm("You teleported, and thank goodness you read the manual! You made it safely to your dad's house, but your car caught fire, whoops!")
                    } else {
                        confirm("Oh no! The computer didn't understand your answer so Father's day was deleted, NO!!!!!!")
                    }
                    if (traffic === 'teleport') {
                        confirm("But your dad got your present, congrats!")
                    } else {
                        confirm("Also, NASA ain't comin' to rescue you, you're done for...")
                    }
            }
    }
} else {
    confirm("Well that was a waste of time...")
}


#2

Erm... if I were to add a single quotation mark inside a string, wouldn't it terminate the string, then will all the code after that not be read as a string?
If so, I might know what's my SyntaxError.


#3

if (traffic === 'portal") {

here you used a single quote to start a string and a double quote to close it. That does not work and the string will remain open causing a lot of trouble (take a look at the color of your code to see where it really ends). You can use both ' and " for strings but you should be consistent as they only close there respective type and are just chars for the other one.


#4

I did that, but I got another error. The new error is SyntaxError: unexpected token :


#5

thanks for everything. i just used tampermonkey'
s syntax check to fix the problem. Thanks anyway!


#6

Also, to anyone wondering what went wrong, I had two colons in the wrong spots, both of them were before the CASE token.


#7

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.