This is my first ever JS game. I have an issue that I’m trying to fix… For some reason if the user chooses “rope”, then the computerChoice displays as a number instead of the actual string associated with that number.
What is causing this issue? Also, please feel free to tell me where my syntax is wrong, any spacing issues etc (unnecessary semi colons etc).
thanks!
var userChoice = prompt("Do you choose rock, paper or scissors... or rope?");
var computerChoice = Math.random();
if (computerChoice < 0.25) {
computerChoice = "rock"
} else if(computerChoice < 0.5) {
computerChoice = "paper"
} else if(computerChoice < .75) {
computerChoice === "scissors"
}
else {
computerChoice === "rope"
}
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 if(choice2 === "paper") {
return "paper wins";
}
else {
return "rope beats rock"
}
}
else if(choice1 === "paper") {
if(choice2 === "rock") {
return "paper wins";
}
else if (choice2 === "scissors") {
return "scissors wins";
}
else {
return "Both players lose";
}
}
else if(choice1 === "scissors") {
if(choice2 === "rock") {
return "rock wins";
}
else if(choice2 === "paper") {
return "scissors wins";
}
else {
return "scissors cuts rope";
}
}
else if(choice1 === "rope") {
if(choice2 === "rock") {
return "rope beats rock";
}
else if(choice2 === "paper") {
return "both players lose";
}
else {
return "scissors beats rope";
}
}
else {
return "Are you even taking this seriously?";
}
};
compare(userChoice, computerChoice)