New choices


#1


I tried to make a game a little longer and if answers are same I wanted to ask computer to make him a new choice, but something is wrong. When i submit my code and choose rock the, answer is always "paper wins", doesn't matter if computer's choice is scissors or paper it's all same "paper wins". And same with the rest of my code, please help guys. Sorry for my english :smiley:


var userChoice = prompt("Do you choose rock, paper or scissors?");
var computerSign = function(){
    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 computerChoice = computerSign()

var compare = function(choice1, choice2){
    if (choice1===choice2){
        var userChoice = prompt("one more time, the result is a tie");
        var computerChoice = computerSign()
        choice1 = userChoice
        choice2 = computerChoice
        compare(userChoice, computerChoice);
    }
    
    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 === "paper"){
            return "scissors wins";
        }
        else {
            return "rock wins";
        }
    }
}
compare(userChoice, computerChoice)


#2

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.