Urgent help needed! Stuck, says syntax error


#1

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 === paper, choice2 === rock)
    {
        return "paper wins";
    }
    else if (choice1 === paper, choice2 === scissors)
    {
        if (choice2 === scissors)
        {
            return "scissors wins";
        }
        else
        {
            return "paper wins";
        }
        
    }
}};
{
    if (choice1 === choice2) 
    {
        return "The result is a tie!";
    }
     else
    { 
        if (choice1 === rock, choice2 === scissors)
        {
            return "rock wins";
        }
        else
        {
            return "paper wins";
        }
    }};

#2

Hey @boardrunner71238! 2 problems:

First: you didnt need 2 brackets here just one:

Secondly:
change all the returns bellow this:

to console.log()

Hope this helped!


#3

i now have this

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 === paper, choice2 === rock)
    {
        return "paper wins";
    }
    else if (choice1 === paper, choice2 === scissors)
    {
        if (choice2 === scissors)
        {
            return "scissors wins";
        }
        else
        {
            return "paper wins";
        }
        
    }
};
{
    if (choice1 === choice2) 
    {
        console.log("The result is a tie!");
    }
     else
    { 
        if (choice1 === rock, choice2 === scissors)
        {
            console.log("rock wins");
        }
        else
        {
            console.log("paper wins");
        }
    };

and it is saying unexpected end of input?


#4

@amanuel2 is correct about the }}; which close your function too early but using console.log doesn't change anything and might just confuse the test function. So essentially due to closing the function too early important parts are now outside of the function which leads to problems. Also keep an eye on your conditions:

  if (choice1 === rock, choice2 === scissors)

without "" rock and scissors are treated as variable names. Btw do you know how the comma operator works or what do you expect it to do?

Ps: For the formatting you may have a look at jsbeautifier.org