I\'m working on making my first game (Rock Paper Sissors) and I ran into an issue where when the userChoice is scissors and the com
var compare = function (choice1, choice2)
{
if (choice1 === choice2)
{
return "The result is a tie!";
}
else
{
if(choice1 === "rock")
{
if(choice2 === "paper")
{
return "Paper beats rock. Computer Wins.";
}
else
{
return "Rock beats scissors. You win.";
}
}
else
{
if(choice1 === "paper")
{
if(choice2 === "rock")
{
return "Paper beats rock. You Win.";
}
else
{
return "Scissors beat paper. Computer Wins."; }
}
if(choice1 === "scissors")
{
if(choice2 === "rock")
{
return "Rock beats scissors. Computer Wins.";
}
else
{
return "Scissors beat paper. You Win."; }
}
}
}
};
var r = function(user)
{
while(user < 0 | user >3)
{user = prompt("Please don't act oversmart. Press '1' for rock, '2' for paper, and '3' for scissors.");
}
if(user === "1")
user = "rock";
else
{
if(user === "2")
{user = "paper";}
else
{user = "scissors";}
};
console.log("You chose: " + user);
computerChoice = Math.random()
if(computerChoice <= 0.33)
{
computerChoice = "rock";
}
else
{
if(computerChoice > 0.33 && computerChoice <=0.66)
{computerChoice = "paper";}
else
{computerChoice = "scissors";}
}
console.log("The computer chose: "+computerChoice)
console.log(compare(user, computerChoice));
if(user===computerChoice)
{
userChoice = user;
return "1";}
};
var userChoice = prompt("Press '1' for rock, '2' for paper, and '3' for scissors")
var computerChoice;
var a = r(userChoice);
if(a === "1")
{//console.log("1");
while(userChoice === computerChoice)
{
var a = prompt("Since there was a tie, please choose again. Press 1 for rock, 2 for paper and 3 for scissors.")
var b = r(a);
if(b !== "1")
{break;}
}
}