Your code returned 'Scissors wins' instead of 'undefined' when the inputs are scissors and rock


#1

My program seems to work fine, but I keep getting:

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

??How do I solve it??

This 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 compare = function(choice1 , choice2) {
    if (choice1 == choice2) return "The result is a tie!";
    else if (choice1 == "Rock") return (choice2 == "Scissors") ? "Rock wins" : "Paper wins" ;
    else if (choice1 == "Paper") return (choice2 == "Rock") ? "Paper wins" : "Scissors wins" ;
    else return (choice2 == "Rock") ? "Rock wins" : "Scissors wins" ;
}
do  var userChoice = prompt("Do you choose (r)ock, (p)aper or (s)cissors?");
    while ((userChoice == null || userChoice == "") || ( userChoice != "R" && userChoice != "r" && userChoice != "rock" && userChoice != "Rock" && userChoice != "P" && userChoice != "p" && userChoice != "paper" && userChoice != "Paper" && userChoice != "S" && userChoice != "s" && userChoice != "scissors" && userChoice != "Scissors"));

userChoice = (userChoice == "R" || userChoice == "r" || userChoice == "rock" || userChoice == "Rock") ? "Rock" :
             (userChoice == "P" || userChoice == "p" || userChoice == "paper" || userChoice == "Paper") ? "Paper" :
             "Scissors";
console.log("You choose" , userChoice);

var computerChoice = Math.random();
//console.log(computerChoice);

/*if (0<=computerChoice&&computerChoice<=0.33) computerChoice = "Rock";
//if (0<=computerChoice&&computerChoice<0.34) computerChoice = "Rock";
else if (0.33<computerChoice&&computerChoice<=0.66) computerChoice = "Paper";
//else if (0.34<=computerChoice&&computerChoice<0.67) computerChoice = "Paper";
else computerChoice = "Scissors";*/

computerChoice = computerChoice < 0.34 ? "Rock" :
                 computerChoice < 0.67 ? "Paper" :
                 "Scissors" ;
console.log("I choose" , computerChoice);

compare(userChoice , computerChoice);

#2

-1
The code-checker is relying on you doing EXACTLY as is asked.
They want you to return the string Values in all-lowercase like
paper wins
rock wins
scissors wins
Have look at a compilation
http://www.codecademy.com/forum_questions/559dcb4be39efe550f00006b

-2
If you had followed the instructions, following code-line's would have produced a true

console.log("choice1 && choice2  argument's are equal");
console.log("1 "+ (compare("paper","paper")==="The result is a tie!"));
console.log("2 "+ (compare("rock","rock")==="The result is a tie!"));
console.log("3 "+ (compare("scissors","scissors")==="The result is a tie!"));

console.log("choice1 argument 'paper'");
console.log("4 "+ (compare("paper","rock")==="paper wins"));
console.log("5 "+ (compare("paper","scissors")==="scissors wins"));

console.log("choice1 argument 'rock'");
console.log("6 "+ (compare("rock","paper")==="paper wins"));
console.log("7 "+ (compare("rock","scissors")==="rock wins"));

console.log("choice1 argument 'scissors'");
console.log("8 "+ (compare("scissors","paper")==="scissors wins"));
console.log("9 "+ (compare("scissors","rock")==="rock wins"));

-3 Not using curly-brackets-{ } to encapsulate code-which-stands-together
is a dangerous affair,
and will make it more difficult to expand/change the code.
Have a read through some code-convention's as is used by many
and has been written by Crockford
http://javascript.crockford.com/code.html

-4

nice to know

You could test in labs.codecademy.com
choose Javascript
You will get a split-screen
In the left-hand-side you paste-in your code
click on the Run button.
The right-hand-side is the console

There you would get some suggestions
using strict comparison in cases like
userChoice === null instead of your userChoice == null
and
userChoice === "" instead of your userChoice == ""
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Expressions_and_Operators