I was able to do it with the var computerChoice = Math.random(); … and turning that variable into rock, paper or scissors… but now I can't get the variable 'winner' to change so that it prints out the results. It just keeps printing out 'undefined'. Help?
var choice1 = userChoice;
var choice2 = computerChoice;
var winner = "undefined";
var compare = function (choice1, choice2) {//start function
if (choice1 === choice2) {
winner = "Tie game!";
} else if (choice1 === "rock") {
if (choice2 === "scissors") {
winner = "rock wins";
} else {
winner = "paper wins";
}
} else if (choice1 === "paper") {
if (choice2 === "rock") {
winner = "paper wins";
} else {
winner = "scissors wins";
}
} else {
if (choice2 === "paper") {
winner = "scissors wins";
} else {
winner = "rock wins";
}
}
}//end function
confirm("You chose: " + userChoice + "\nSystem: " + computerChoice + "\nOutcome: " + winner);
compare(userChoice,computerChoice);
</script>
comparebefore you callconfirm.