This forum is now read-only. Please use our new forums! Go to forums
Going batshit crazy from debugging
Hey, so I’m going batshit crazy from trying to debug this stupid code. I have read pretty much every post people have written about this section, and I have copied and pasted all of the right answers from those posts and compared it to mine, and it is identical, yet it still is not working.. So here’s my code. Please, don’t just copy and paste some code, I would love it if someone could just point out what is wrong, so I learn and don’t make the same mistake again. I want to debug it, not just remove it and copy and paste someone else’s code.
At first the syntaxError I got was “Unexpected token { “, but I managed to solve that, now I get the syntaxError “Unexpected token else”, so it seems that one of my “else” is acting up, but I can’t seem to understand what? Thanks in advance.
Here’s my code:
var userChoice = prompt(“Do you choose rock, paper or scissors?”); var computerChoice = Math.random();
//computer choice if (computerChoice < 0.34) { computerChoice = “rock”; }
else if(computerChoice <= 0.67) { computerChoice = “paper”; }
else { computerChoice = “scissors”; } console.log(“Computer: “ + computerChoice);
//FUNCTION var compare = function(choice1, choice2) {
//if tie if(choice1 === choice2) { return “The result is a tie!” }
//part 1 else if(choice1 === “rock”) { if(choice2 === “scissors”) { return “rock wins”; }
else { return “paper wins”; }
}
//part 2 else if(choice1 === “paper”) { if(choice2 === “rock”) { return “paper wins”; } } }
else { return “scissors wins”; }
} //part 3 else if(choice1 === “scissors”) { if(choice2 === “rock”) { return “rock wins”; }
else { return “scissors wins”; } } };
compare(userChoice, computerChoice);
Answer 5602536be39efe5c29000314
Have a read http://www.codecademy.com/forum_questions/559dcb4be39efe550f00006b the setup of the IF ELSE-IF statement.
Answer 5603111651b8871c550003a6
I’m having the same problem, same thing as you, I double, triple, quadruple^10293 checked and I couldn’t find what the problem is. We both have the curly brackets { } code blocks right but it’s just annoying not know what the problem is really..
Answer 5603374a86f5523d2f000454
You are missing a semi-colon after “The result is a tie” in your code below.
//if tie if(choice1 === choice2) { return “The result is a tie!” }
Also, you have too many curly brackets in your code, for example in part 2:
//part 2 else if(choice1 === “paper”) { if(choice2 === “rock”) { return “paper wins”; } } }
Popular free courses
- Free Course
Learn SQL
In this SQL course, you'll learn how to manage large datasets and analyze real data using the standard data management language.Beginner friendly,4 LessonsLanguage Fluency - Free Course
Learn JavaScript
Learn how to use JavaScript — a powerful and flexible programming language for adding website interactivity.Beginner friendly,11 LessonsLanguage Fluency - Free Course
Learn HTML
Start at the beginning by learning HTML basics — an important foundation for building and editing web pages.Beginner friendly,6 LessonsLanguage Fluency