<PLEASE USE THIS TEMPLATE TO HELP YOU CREATE A GREAT POST!>
I want to create another options to the game, so I copied the final code to a JavaScript editor, but everytime I run it, I get an error on line 10
<Below this line, add a link to the EXACT exercise that you are stuck at.>
<In what way does your code behave incorrectly? Include ALL error messages.>
The error reads “Incompatible types”
<What do you expect to happen instead?>
I also trying to run just:
var computerChoice = Math.random();
console.log(computerChoice)
but I get the same error, with or without semicolons on line 10
var userChoice = prompt("Do you choose rock, paper or scissors?");
var computerChoice = Math.random();
if (computerChoice < 0.34) {
computerChoice = "rock";
} else if(computerChoice <= 0.67) {
computerChoice = "paper";
} else {
computerChoice = "scissors";
} console.log("Computer: " + computerChoice);
var compare = function(choice1, choice2) {
if(choice1 === choice2) {
return "The result is a tie!";
}
else if(choice1 === "rock") {
if(choice2 === "scissors") {
return "rock wins";
}
else {
return "paper wins";
}
}
else if(choice1 === "paper") {
if(choice2 === "rock") {
return "paper wins"
}
else {
return "scissors wins"
}
}
else if(choice1 === "scissors") {
if(choice2 === "rock") {
return "rock wins"
}
else {
return "scissors wins"
}
}
}
console.log( compare(userChoice,computerChoice) )