Discuss Scratch
- Discussion Forums
- » Advanced Topics
- » Learning JavaScript: could use some support and help
- turkey3_test
-
1000+ posts
Learning JavaScript: could use some support and help
Prior to JavaScript, I only knew a little CSS, HTML, Java, and Python, but hardly much at all. I decided to learn JavaScript, and am doing so on Codecadamy. I am about 28% finished with the course but am stuck on a Rock Paper Scissors game part. Here is my code:
The problem is the “else” near the bottom. When I run the code, I get SyntaxError: Unexpected token ‘else’. Can you help me debug this? Thanks! 
var userChoice = prompt("Do you choose rock, paper or scissors?"); var computerChoice = Math.random(); //random value between 0 and 1 if (computerChoice < 0.34) { computerChoice = "rock"; } else if(computerChoice <= 0.67) { computerChoice = "paper"; } else { computerChoice = "scissors"; } var compare = function(choice1, choice2) { if (choice1 === choice2); { return "The result is a tie!"; } if (choice1 === "rock"); { if (choice2 === "scissors"); { return "rock wins"; } else; { return "paper wins"; } } }

- danwoodski
-
100+ posts
Learning JavaScript: could use some support and help
Try getting rid of the semi-colons after the if/else statements (instead of else; put just else)
- turkey3_test
-
1000+ posts
Learning JavaScript: could use some support and help
I did and the same thing happens. Try getting rid of the semi-colons after the if/else statements (instead of else; put just else)
- turkey3_test
-
1000+ posts
Learning JavaScript: could use some support and help
Never mind, it worked. Thanks so much!I did and the same thing happens. Try getting rid of the semi-colons after the if/else statements (instead of else; put just else)
- veggieman001
-
1000+ posts
Learning JavaScript: could use some support and help
Conceptually, just remember that if and else aren't lines themselves; they require what's enclosed in the brackets (which is their argument). If anywhere, it would make the most sense to but a semicolon after the curly brackets.
- Discussion Forums
- » Advanced Topics
-
» Learning JavaScript: could use some support and help