Wednesday, 11 September 2013

Simple program but cant figure out why it doesn't work

Simple program but cant figure out why it doesn't work

i just started learning javascript and now im trying to make a "simple"
rock. paper/scissors game.
However when i try to run it i get the error: UserChoise is not defined.
But i enter the value when promted for it. Here is my code:
var userChoice = prompt("Do you choose rock, paper or scissors?") ;
var computerChoice = Math.random();
if (computerChoice<0.33) {
console.log("rock");
} else if (computerChoice>0.34===0.66){
console.log("paper");
} else (computerChoice>0.67===1);{
console.log("scissors");
}
var compare = function(choise1,choise2){
if (choise1 === choise2) {
return("The result is a tie!");
}if (choise1 === "rock" ){
if (choise2 === "scissors"){
return("rock wins");
} else if (choise2 === "paper") {
return("paper wins");
}
}
if (choise1 === "paper" ){
if (choise2 === "rock"){
return("paper wins");
} else if (choise2 === "scissors") {
return("scissors wins");
}
}
if (choise1 === "scissors" ){
if (choise2 === "rock"){
return("rock wins");
} else if (choise2 === "paper") {
return("scissors wins");
}
}
};
compare(userChoise,computerChoise);

No comments:

Post a Comment