What if choice1 is scissors? PROBLEM, PLEASE HELP!


#1


"SyntaxError: Unexpected token else" The problem started to occur near the end of my code, I was on the choice1 is scissors part.


var userChoice = prompt("Do you choose rock, paper or scissors?");
var computerChoice = Math.random();
if (computerChoice < 0.34) {
	computerChoice = "rock";
} else if(computerChoice <= 0.67) {
	computerChoice = "paper";
} else {
	computerChoice = "scissors";
} console.log("Computer: " + computerChoice);
var compare = function(choice1, choice2) {
    if(choice1 === choice2) {
     return "The result is a tie!";
}
 else if(choice1 === "rock") {
     if(choice2 === "scissors"){
     return "rock wins"; 
     }
     else {
         return "paper wins"; 
     }
}
  else if(choice1 === "paper") {
     if(choice2 === "rock") {
     return "paper wins"; 
     }
     else {
         return "scissors wins";
     }
  }
}
else if(choice1 === "scissors") {
     if(choice2 === "paper") {
     return "scissosr wins"; 
     }
     else {
         return "rock wins";
     }
}
 compare(userChoice, computerChoice);


#2

Check your closing braces. Is the function closed too early?


#3

I don't know what's wrong with my closing brackets, they seem fine, even though the problem is probably occurring because of them.


#4

If you want to be a programmer, then solve this.


#5

It's definitely not me, there's nothing wrong with my code. I'm 100% sure that's it's an integrated problem. I went back to redo my old code, did the exact same thing, came out to be "error syntax". I looked at tutorials on YouTube, they did the exact same thing as me, didn't work out for me. Looked at other forums, copied their code, which was the exact same as mine, didn't work. I did it in the format that codeacademy's "hint" provided, it came out to be an "Error."


#6

That is the problem. Function is closed too soon


#7

Done that, still doesn't work. I also copied and pasted others code in this forum that they got through with, didn't work for me.


#8

Please show us your current compare function code. Thanks.


#9

It's the exact same, when I changed it too two brackets, it didn't work. The way it is, it works, it's the last bit of code, where it starts from else if(choice1 === "scissors") { , where problems started to occur.
Edit: I got it to work, I just didn't add the last bit of code for the last exercise, so it's sorta incomplete, but it works and it gave me the pass.


#10

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