Step 9: Continuing The Game


#1

So I was trying to make the game continue even if there was a tie. I managed to prompt the user to choose again if there was a tie but everytime I run the code it prints out "This game can't handle two ties in a row!" What am I doing wrong?

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) {
       var userAnswer = prompt("It's a tie! Do you wanna play again?")
        if(userAnswer === "yes"){
            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);
       
       if (choice1 === choice2) {
       return "This game can't handle two ties in a row!"
       }
     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"
            }}
            }else{
            return "Okay then, see you later!";
        }} 
   
        
        /*This is were the replay ends*/
    
        
       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"
            }}}
            compare(userChoice,computerChoice);

#2

This advice is going to sound conceited and/or condescending, but please don't take it that way. As it turns out, this challenge appears before many of the important modules, particularly loops. I recommend setting this part of the challenge aside, for now, and return when you have completed the track. By then you will be sufficiently armed for the task of making this into a proper game. Happy coding!


#3

No, I didn't take it that way at all. Like you said I will focus on finishing the track for now. Thank you for your attention.