What's wrong with my code?


#1

I have walked through my code a couple of times and cannot see what's causing the error. Thank you in advance for your assistance.

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

SyntaxError: Invalid or unexpected token

`
var user = prompt("Your team is up two points and ten seconds are left, a fastbreak is coming at you, what is your move? Stop the ball, foul or let them shoot?").toLowerCase();

switch(user) {
case 'stop the ball':
var pass = prompt("Player passed the ball");
var block = prompt("You blocked the shot");
if(pass === "You win" || block === "You win") {
console.log("You won the game!”);
} else {
console.log("Smart Decision");
}
break;
case 'foul':
var onTheShot = prompt("To the freethrow line");
var hardFoul = prompt("Two shots and the ball back");
if(onTheShot === "Foul" && hardFoul === "Foul") {
console.log("We had time, you didn't need that");
} else {
console.log("What the heck are you doing?!");
}
break;
case 'let them shoot':
var make = prompt("You allowed them to shoot the three?");
var miss = prompt("Shot missed, what a relief.");
if(make === prompt("Why a three?") || miss === prompt("They still shot it!") {
console.log("That's the game.");
} else if {
console.log("You dodged a bullett");
}
break;
default:
console.log("Couldn’t handle the pressure, huh?");
}


#2

Does it tell you which line the syntax error is?


#3

Hello,

It does not tell me what line the error has occurred on.


#5

Okay well I'm on line 5 and nothing is wrong so far, but I wanted to ask about using variables such as pass and block to prompt a string. Prompt is used to ask questions, and you are just using prompt for a statement. If you want to do a statement, use confirm, but I don't think you want to do that either.
My advice is that maybe you should use var pass and ask a question inside of prompt then do the same for block. Inside of your if statement's condition, the variables pass and block want to be equal to "You win" so you need a way to make the answer to the prompted questions "You win", or change both the question/answer choices, and your if condition.
Does any of this make sense haha I'm not the best at explaining?


#6

Yes, what you explained makes sense. So it would probably be easier to use yes/no questions for this exercise?


#7

Wow, okay so I found the syntax error(s). They were simple but here we go...

You didn't close your if condition. You opened it, and used two sets of parenthesis, but you needed an extra parenthesis on the end.

You don't need an else if statement, because there is no condition. You just wanted to use an else statement.

So these are the reasons that your code didn't work, but I strongly suggest going back into it and fixing the prompt questions I mentioned. There are quite a few and I can point them out really quick. You asked if it would be better to use yes and no questions inside of this exercise and the answer is yes. 100% that would make a difference. So here are the prompt questions I think you might want to fix,

After all of those are yes/no questions, you need to remember to go into the if statements condition and change it to make sure that the string is now yes or no. (A tip is also using .toLowerCase or .toUpperCase after your prompt statement like you did in line one.)

If you have any trouble with this let me know! I really hope this helps. :slight_smile:


#8

Thank you for your assistance. I will go back in and give it another shot. Thanks again.


#9

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