Build "Rock, Paper, Scissors" .8


#1

I keep getting this error message. Your code returned 'scissor wins' instead of 'undefined' when the inputs are scissors and paper... This is my code. Help please I've been at this for a while.

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)
{
string="The result is a tie!";
return string;
}
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 === "rock")
    {
        return "rock wins"
    }
    else
    {
        return "scissors wins"
    }
}
};
compare(userChoice, computerChoice)

#2

@timj14,

1

they expect

"scissors wins"

you use

"scissor wins"

2

Please re-edit your Post

  • select your code in the Post
  • then =click= on the </>-symbol-of-this-editor

Your code will then be in a pre-code state
and you will be able to make/present the proper indentations.

3

For a guidance how to write your code in an acceptable format
= http://javascript.crockford.com/code.html


#3

Thank you it worked. I appreciate it.


#4

@timj14,
But you did not re-edit your original-Post....