Help?


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

compare(1,2);
`


#2

which exercise? What is the error message? I would call the function with as arguments userChoice and computerChoice, not 1 and 2


#3

Oops, try again. Your code returned 'paper wins' instead of 'undefined' when the inputs are scissors and paper

what does it mean?


#4

these lines:

else if(choice2 === "rock")
    {
        if(choice1 === "scissors")

why do you have choice2 in the else if? So far, you always has choice1 in the else if, and choice2 in the if statement


#5

i changed it but it still not works.

Oops, try again. Your code returned 'paper wins' instead of 'undefined' when the inputs are scissors and paper


#6

please post an updated version of your code with format/markup:


#7

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

#8

look at this:

else if(choice1 === "scissors")
    {
        if(choice2 === "rock")
        {
            return "rock wins";
        }
        else
        {
            return "paper wins";
        }
    }

if choice1 is paper, and choice2 is rock, rock wins. But else (which means choice2 is paper) paper beats scissors? I would change, make if choice2 == paper, and then return scissors wins, and else should then be rock wins