While loop doesnt work..need help


#1

var userChoice, x = 0;
var computerChoice = Math.random();

//converts computer choice to rock, paper or scissors
if (computerChoice < 0.34)
{
computerChoice = "rock";
}
else if(computerChoice <= 0.67)
{
computerChoice = "paper";
}
else
{
computerChoice = "scissors";
}

//checks user choice for a valid entry
while(x = 0)
{
userChoice = prompt("rock, paper or scissors man!!")
if(userChoice == "rock")
{x = 1;}
else if(userChoice == "paper")
{x = 1;}
else if(userChoice == "scissors")
{x = 1;}
};

var compare = function(userChoice, computerChoice)
{
console.log("Computer: " + computerChoice);
console.log("User: " + userChoice);

if(userChoice === computerChoice)
   {return "The result is a tie!";}
else if(userChoice === "paper" && computerChoice === "rock")
    {return "paper wins";}
else if(userChoice === "paper" && computerChoice === "paper") 
    {return "scissors win";}  
else if(userChoice ===  "scissors" && computerChoice === "rock")
    {return "rock wins";}
else if(userChoice ===  "scissors" && computerChoice === "paper")
    {return "scissors wins";}
else if(userChoice ===  "rock" && computerChoice === "scissors")
    {return "rock wins";}
else if(userChoice ===  "rock" && computerChoice === "paper")
    {return "paper wins";}

};
compare(userChoice, computerChoice);


#2

1

The while-loop-condition should contain a comparison-operator === or ==
You are using an assignment-operator =

2

The console.log() statement's should stand outside of your compare =function=

The console.log("User: " + userChoice); could be part of your while-loop, at the end, just before leaving the loop.

3

Read the truth-table in
= http://www.codecademy.com/forum_questions/559dcb4be39efe550f00006b
and check if you have covered each of the nine possibilities
in your compare =function= ( i am sure you missed one... )

= = = = = = = = = = = = = = = = = = = =

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

references

www.crockford.com --> for most respected guide-line in Javascript
like coding convention
www.crockford.com
http://javascript.crockford.com/code.html
http://javascript.crockford.com/survey.html