<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.>
https://www.codecademy.com/courses/javascript-beginner-en-Bthev-mskY8/1/5?curriculum_id=506324b3a7dffd00020bf661
<Below this line, in what way does your code behave incorrectly? Include ALL error messages.>
I am building a simple game (rock, paper, scissors). I’ve created an if condition to print an error message when the user inputs an invalid answer but I’m unable to figure out how to stop further execution of my code when the condition is true. And even if the condition is false the error message gets printed
var userChoice = prompt("Do you choose rock, paper or scissors?");
if (userChoice != "rock" || "paper" || "scissors") {
console.log("This isn't a valid answer! Please try again");
}
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") {
console.log("Rock wins");
}
else {
console.log("Paper wins");
}
}
else if (choice1=== "paper") {
if (choice2 === "rock") {
console.log("Paper wins");
}
else {
console.log("Scissors win");
}
}
else if (choice1 === "scissors") {
if (choice2 === "paper") {
console.log("Scissors win");
}
else {
console.log("Rock wins");
}
}
};
compare(userChoice, computerChoice);