Code Your Own Adventure, SyntaxError: Unexpected token case


#1

Hello, CA community. This is my first time posting on this board. I usually try to figure out my code errors on my own, but this is driving me crazy. I've gone over it several times, even re-written it a few, and it still says there is a syntax error. Am I missing something?


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


Error message says: SyntaxError: Unexpected token case


var vampire = prompt("Greetings, adventurer. You stand before the ten-foot door of a dreary mansion. Behind you, lightning cracks as if warning you away from your destination. Your heart pounds in your chest and your palms grow slick with sweat, but you are determined to enter this place. You have heard rumor that a gorgeous vampire lives between these walls and you wish to meet him. How do you enter, do you KNOCK, BREAK DOWN THE DOOR, or PICK THE LOCK?").toUpperCase();

switch (vampire) {
    case 'KNOCK':
        var intelligenceCheck = prompt("As you raise your fist to the door, a booming voice calls from behind the barrier. 'GO AWAY!' A wave of apprehension slams into you and you almost fall to your knees. You are being tested! Are you SMART (YES or NO)?").toUpperCase();
        var wisdomCheck = prompt("Will you BACK DOWN?").toUpperCase();
        if(intelligenceCheck === 'YES' && !wisdomCheck === 'YES') {
          console.log("You may be strong-willed, but you're no fool. This is a magic spell and this vampire is too strong for you. You lower your hand and leave without knocking, probably saving your life! You LIVE!");
        }
        else {
          console.log("Some say bravery and foolishness go hand-in-hand. You're not sure which failed you here, but you knock, despite the dread filling your body. The door opens and the last thing you see is a pair of red eyes. Looks like you DIED!");
        }
    break;
    case 'BREAK DOWN THE DOOR':
            var strengthCheck = prompt("There is no time to lose! You decide that you're just going to break down the door. You back up a step and carefully align your foot with the door. One good kick should do it...maybe. Are you STRONG (YES or NO)?").toUpperCase();
            var dexterityCheck = prompt("You didn't even need to kick that hard. The door swings open, seemingly on its own accord and you tumble into a dark corridor. Just as you are about to land, you hear the unmistakable 'Click' of a trap being sprung. Are you NIMBLE?").toUpperCase();
            if (strengthCheck === 'YES' || dexterityCheck === 'YES') {
                console.log("You definitely don't like the sound of that 'Click'. Every instinct you have is telling you to get out of Dodge and whether it is through sheer strength of excellent footwork, you manage to throw yourself backward and back out of the door. Just as you clear the barrier, you hear creaking of gears and the floor you *were* standing on falls away. The mansion door snaps shut but you are already free and clear. You LIVE to fight another day!");
            }
            else {
                console.log("You definitely don't like the sound of that 'Click'. Every instinct you have is telling you to get out of Dodge and you try to fling yourself back toward the open door. Unfortunately, whether your muscles give out or you stumble over your feet, you're not able to make it to safety. The floor beneath you falls away and you find yourself falling, falling, falling into a dark abyss. You get the feeling your landing won't be pretty. Looks like you DIED!"); 
    break;
    case 'PICK THE LOCK':
            var constitutionCheck = prompt("Luckily, you happen to be a whiz at lock-picking. You brought along a kit, just in case. You kneel down at the door and get to work, but after ten minutes you realize this lock is very strong. You can still pick it, but as the sweat run into your eyes and your legs begin to cramp, you wonder if you're going to hold this position for long enough. Can you take the strain (YES or NO)?").toUpperCase();
            var charismaCheck = prompt("You work at the lock for another thirty minutes, your hands trembling and the muscles of your back screaming for mercy. Your hands get slick with your sweat and the pressure in your neck becomes almost unbearable. You're just about to give up when the door clicks open. Before you, a beautiful child with long, jet-black hair stands. She smiles softly. 'Hello, stranger.' Is your response ELOQUENT?").toUpperCase();
            if (constitutionCheck === 'YES' && charismaCheck === 'NO') {
                console.log("The beauty of the child in front of you causes you to stammer out an ineloquent response. She looks at you, her overly-large eyes blinking with wisdom that she should not hold. She shakes her head slowly and sighs. 'You are not the one I am waiting for. You should leave this place...before I get hungry.' She flashes you a toothy smile and her eyes glow with an unnatural light. That's when you notice her canines are a little too sharp. Terrified, you scramble backward and she closes the door. You feel as if you narrowly escaped death. You LIVE!");
                else if (constitutionCheck === 'YES' && charismaCheck === 'YES'){
                    console.log("You bow deeply before the child and take her hand. Her skin, flawless and creamy, is also a little cold to the touch. However, you don't let that stop you. You speak eloquently of her beauty and grace, all while trying to get a glimpse inside the house so that you can see if there truly is a monster in its depths. The girl laughs softly as you speak to her and you can tell she is pleased. 'Would you like to come in and get a better view of what you are seeking, stranger?' She asks it softly and her voice is so enchanting you don't even think to deny her. You follow her into the depths of the mansion...only to be blinded by darkness the moment the doors close behind you. The last thing you hear is that sweet, lilting voice. 'I do love a stranger with a smooth tongue.' Looks like you DIED! Too bad.");
                    else {
                        console.log("You work at the lock for another twenty minutes, your hands trembling and the muscles of your back screaming for mercy. Your hands get slick with your sweat and the pressure in your neck becomes unbearable. You can't go any longer. The lock pick falls to the ground and you collapse in exhaustion. Just as you are about to gather your energy and try again, a deep-rooted instinct tells you that you're better off walking away. You can't help but to listen to it and as you're walking away from the mansion, a voice tells you to be grateful that you lived.");
    break;
    default:
        console.log("That wasn't one of the options, adventurer.");
}

I appreciate any insight!


#2

make sure you've closed all brackets(})


#3

HI this case

 case 'PICK THE LOCK':
    var constitutionCheck = prompt("Luckily, you happen to be a whiz at lock-picking. You brought along a kit, just in case. You kneel down at the door and get to work, but after ten minutes you realize this lock is very strong. You can still pick it, but as the sweat run into your eyes and your legs begin to cramp, you wonder if you're going to hold this position for long enough. Can you take the strain (YES or NO)?").toUpperCase();
    var charismaCheck = prompt("You work at the lock for another thirty minutes, your hands trembling and the muscles of your back screaming for mercy. Your hands get slick with your sweat and the pressure in your neck becomes almost unbearable. You're just about to give up when the door clicks open. Before you, a beautiful child with long, jet-black hair stands. She smiles softly. 'Hello, stranger.' Is your response ELOQUENT?").toUpperCase();
    if (constitutionCheck === 'YES' && charismaCheck === 'NO') {
        console.log("The beauty of the child in front of you causes you to stammer out an ineloquent response. She looks at you, her overly-large eyes blinking with wisdom that she should not hold. She shakes her head slowly and sighs. 'You are not the one I am waiting for. You should leave this place...before I get hungry.' She flashes you a toothy smile and her eyes glow with an unnatural light. That's when you notice her canines are a little too sharp. Terrified, you scramble backward and she closes the door. You feel as if you narrowly escaped death. You LIVE!");
    else if (constitutionCheck === 'YES' && charismaCheck === 'YES'){
        console.log("You bow deeply before the child and take her hand. Her skin, flawless and creamy, is also a little cold to the touch. However, you don't let that stop you. You speak eloquently of her beauty and grace, all while trying to get a glimpse inside the house so that you can see if there truly is a monster in its depths. The girl laughs softly as you speak to her and you can tell she is pleased. 'Would you like to come in and get a better view of what you are seeking, stranger?' She asks it softly and her voice is so enchanting you don't even think to deny her. You follow her into the depths of the mansion...only to be blinded by darkness the moment the doors close behind you. The last thing you hear is that sweet, lilting voice. 'I do love a stranger with a smooth tongue.' Looks like you DIED! Too bad.");
    else {
        console.log("You work at the lock for another twenty minutes, your hands trembling and the muscles of your back screaming for mercy. Your hands get slick with your sweat and the pressure in your neck becomes unbearable. You can't go any longer. The lock pick falls to the ground and you collapse in exhaustion. Just as you are about to gather your energy and try again, a deep-rooted instinct tells you that you're better off walking away. You can't help but to listen to it and as you're walking away from the mansion, a voice tells you to be grateful that you lived.");

you didn't close the if, else if and else statement and...... in this case you didn't close the else statement

     case 'BREAK DOWN THE DOOR':
            var strengthCheck = prompt("There is no time to lose! You decide that you're just going to break down the door. You back up a step and carefully align your foot with the door. One good kick should do it...maybe. Are you STRONG (YES or NO)?").toUpperCase();
            var dexterityCheck = prompt("You didn't even need to kick that hard. The door swings open, seemingly on its own accord and you tumble into a dark corridor. Just as you are about to land, you hear the unmistakable 'Click' of a trap being sprung. Are you NIMBLE?").toUpperCase();
            if (strengthCheck === 'YES' || dexterityCheck === 'YES') {
                console.log("You definitely don't like the sound of that 'Click'. Every instinct you have is telling you to get out of Dodge and whether it is through sheer strength of excellent footwork, you manage to throw yourself backward and back out of the door. Just as you clear the barrier, you hear creaking of gears and the floor you *were* standing on falls away. The mansion door snaps shut but you are already free and clear. You LIVE to fight another day!");
            }
            else {
                console.log("You definitely don't like the sound of that 'Click'. Every instinct you have is telling you to get out of Dodge and you try to fling yourself back toward the open door. Unfortunately, whether your muscles give out or you stumble over your feet, you're not able to make it to safety. The floor beneath you falls away and you find yourself falling, falling, falling into a dark abyss. You get the feeling your landing won't be pretty. Looks like you DIED!");

#4

Thank you so much, this took me all day and I appreciate it! :grin:


#5

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