I have created a basic rock paper scissors game and i cannot return the result inside the function.
I've been try everything
link console logging the compare and also putting it inside a variable..
console.log(compare) returns undefined for some reason.
Please help
var userChoice = prompt("Do you choose rock, paper or scissors?");
var computerChoice = Math.random();
var result;
if (computerChoice < 0.34) {
computerChoice = "rock";
} else if(computerChoice <= 0.67) {
computerChoice = "paper";
} else {
computerChoice = "scissors";
} console.log("Computer's choice: " + computerChoice);
console.log("Your choice: " + userChoice);
console.log(computerChoice + " vs " + userChoice);
var compare = function(userChoice, computerChoice){
if (userChoice === computerChoice){
return "The result is a tie!";
} else if (userChoice ==="rock"){
if(computerChoice ==="scissors"){
return "rock wins!";
}
else {
return "paper wins!";
}
} else if (userChoice === "paper") {
if(computerChoice === "rock") {
return "paper wins!";
}
else {
return "scissors wins!";
}
} else if (userChoice === "scissors") {
if(computerChoice === "rock") {
return "rock wins!";
}
else {
return "scissors wins!";
}
}
}