Rock, Paper, Siccsors


#1

I'm stuck making the scissors function work. Everytime I try to do it, it says "Syntax Error: unexpected end of script"

{
if(choice1 === choice2)
{
return("The result is atie!")
}
else if(choice1 === "paper")
{
if(choice2 === "rock")
{
return ("paper wins");
}
else(choice2 === "scissors")
{
return ("scissors win");
}
}


#2

I got past that, I'm now stuck on a new problem. My final game doesn't work at all. There's a syntax error.

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

#3

var choice1 = userChoice;
var choice2 = computerChoice;

This is unnecessary, when you're using parameters set in the function you don't have to re-initialize them as local variables with the parameters values. This makes having a function useless essentially. (Also will throw an error)

Delete those lines then at the bottom of your code (past everything else) add this line:

compare(userChoice, computerChoice);

When the computer sees this it knows automatically to replace choice1, and choice2 with userChoice, and computerChoice respectively.

Think of the parameters in the code below as simple "place holders" that wait for you (yes you as the programmer) to give it something to replace the parameters, i.e. the variables userChoice, and computerChoice:

var compare = function(chioce1, chioce2)
//                        ^        ^
//These are just place holders for later when you call the function

#4

I'm now having problems with "an unexpected "else""

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