This forum is now read-only. Please use our new forums! Go to forums
How can I change this to play again if I get a Tie?
var compare = function(choice1, choice2) {
if (choice1 === choice2) {
return "The result is a tie! Play Again";
}
else if (choice1 === "Rock") {
if (choice2 === "Scissors") {
return "Player 1: Rock Wins";
}
else if (choice2 === "Paper") {
return "Computer: Paper Wins";
}
else {
return "Computer: Rope Wins";
}
}
else if (choice1 === "Paper") {
if (choice2 === "Rock") {
return "Player 1: Paper Wins";
}
else if (choice2 === "Scissors") {
return "Computer: Scissors Wins";
}
else {
return "Computer: Rope Wins"
}
}
else if (choice1 === "Scissors") {
if (choice2 === "Rock") {
return "Computer: Rock Wins";
}
else if (choice2 === "Paper") {
return "Player 1: Scissors Wins";
}
else {
return "Computer: Rope Wins"
}
}
};
var userChoice = prompt("Do you choose Rock, Paper or Scissors?");
if (userChoice === "Rock") {
userChoice = "Rock"
console.log("Player 1s Answer: " + userChoice);
}
else if (userChoice === "Paper") {
userChoice = "Paper"
console.log("Player 1s Answer: " + userChoice);
}
else if (userChoice === "Scissors") {
userChoice = "Scissors"
console.log("Player 1s Answer: " + userChoice);
}
else {
userChoice = prompt(userChoice + " is invalid input: " +
"Try Again: \nDo you choose Rock, Paper or Scissors?");
console.log("Player 1s Answer: " + userChoice);
}
var computerChoice = Math.random();
if (computerChoice <= 0.25) {
computerChoice = "Rock";
console.log("Computer's Choice: " + computerChoice);
}
else if(computerChoice <= 0.50) {
computerChoice = "Paper";
console.log("Computer's Choice: " + computerChoice);
}
else if (computerChoice <= 0.75) {
computerChoice = "Scissors";
console.log("Computer's Choice: " + computerChoice);
}
else
{
computerChoice = "Rope";
console.log("Computer's Choice: " + computerChoice);
}
compare(userChoice, computerChoice);
Answer 55fa5404e39efe752100061c
Answer 55ff19d086f552b8ae000003
0 votes
if (choice1 === choice2) {
return prompt("Choose again,rock, paper or scissors?") ;
}
I have tried this but when I try to choose again it only prints out
Computer: rock “rock”
1 comments
Hossam L Kommy over 8 years
even if they were different It doesnt show who wins
Popular free courses
- Free Course
Learn SQL
In this SQL course, you'll learn how to manage large datasets and analyze real data using the standard data management language.Beginner friendly,4 LessonsLanguage Fluency - Free Course
Learn JavaScript
Learn how to use JavaScript — a powerful and flexible programming language for adding website interactivity.Beginner friendly,11 LessonsLanguage Fluency - Free Course
Learn HTML
Start at the beginning by learning HTML basics — an important foundation for building and editing web pages.Beginner friendly,6 LessonsLanguage Fluency
2 comments
I suggest that you should proceed to the next lessons, you will learn there what you are looking for, the for loops, while loops and the do..while loops.. just come back to this game if you already possess enough knowledge to improve this.. :) hope this advice helps..
Thanks, I did try to use a while loop for the input checking, but I couldn’t figure out how to make it NOT an infinite loop, I will definitely come back to this, after I have done the more advanced lessons. Thanks for the advice