<PLEASE USE THIS TEMPLATE TO HELP YOU CREATE A GREAT POST!>
<Below this line, add a link to the EXACT exercise that you are stuck at.>
<Below this line, in what way does your code behave incorrectly? Include ALL error messages.>
I know it must be something simple, but I’m stuck. After I added rope to the exercise, the computer seems to be choosing only scissors/rope option, no matter what. Any ideas what I’m doing wrong?
Here’s a JFiddle link: https://jsfiddle.net/nw32xxja/
var Game = function() {
var userChoice = prompt("Do you choose rock, paper, scissors or... rope?");
var computerChoice = Math.random();
if (computerChoice < 0.24) {
computerChoice = "rock";
}
if (0.24 <= computerChoice < 0.5) {
computerChoice = "paper";
}
if (0.5 < computerChoice <= 0.75) {
computerChoice = "rope";
} else {
computerChoice = "scissors";
}
var compare = function(userChoice, computerChoice) {
if (userChoice === computerChoice) {
return "The result is a tie!";
}
if (userChoice === "scissors") {
if (computerChoice === "paper") {
return "User: scissors, PC: paper. You win.";
}
if (computerChoice === "rope") {
return "User: scissors, PC: rope. You win.";
} else {
return "User: scissors, PC: rock. PC wins.";
}
}
if (userChoice === "paper") {
if (computerChoice === "rock") {
return "User: paper, PC: rock. You win.";
}
if (computerChoice === "rope") {
return "User: paper, PC: rope. PC wins.";
} else {
return "User: paper, PC: scissors. PC wins.";
}
}
if (userChoice === "rock") {
if (computerChoice === "paper") {
return "User: rock, PC: paper. PC wins.";
}
if (computerChoice === "rope") {
return "User: rock, PC: rope. PC wins.";
} else {
return "User: rock, PC: scissors. You win.";
}
}
if (userChoice === "rope") {
if (computerChoice === "paper") {
return "User: rope, PC: paper. You win.";
}
if (computerChoice === "rock") {
return "User: rope, PC: rock. You win.";
} else {
return "User: rope, PC: scissors. PC wins.";
}
} else {
return "Wrong choice! Try again."
}
};
var result = compare(userChoice, computerChoice);
document.getElementById("result1").innerHTML = result;
}