Both Choices are the same


#1

Need some urgent help in this code. I am every time getting a syntax error. Please solve it as soon as possible so that I can proceed coding. I am struck in this code since days and unable to move forward because of a syntax error. Please find the error and correct the code and send it to me in the earliest.
Here is my code:
/*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 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("you: " + userChoice);
console.log("Computer: " + computerChoice);

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";
}
}
else if(choice1 === "paper"){
if(choice2 === "rock"){
return "paper wins";
}
else {
return "scissors wins";
}
}
else if(choice1 === "scissors"){
if(choice2 === "rock"){
return "rock wins";
}
if(choice2 === "paper") {
return "paper wins";
}
}
};

COMPAREuserChoice, computerChoice);

Please do the required corrections in the code itself and send the entire code to me again.

Request you to do the needful as soon as possible.

Best Regards'
Pavan
A JavaScript Learner in Code Academy


#2

There are two problems with your code, the first is where you close your function. This is currently your function:

var compare = function(choice1, choice2){
if(choice1 === choice2){
return "The result is a tie!";
   }
};

remove the };, then everything is fine (the rest of your brackets are fine), so then all the returns are inside the function, the second problem is here:

COMPAREuserChoice, computerChoice);

js is case-sensitive, change COMPARE to compare, and after compare is a bracket missing:

compare(userChoice, computerChoice);