Stuck with the RPS , Help please


#1


Build "Rock,Paper,Scissors"


No message error but when I choose 1 of the three choices , I get the computer move but not the score .(either rock wins/scissor wins/paper wins/The result is a tie!)


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(userChoice,computerChoice){
    if(userChoice === computerChoice){
        return "The result is a tie!";}
    else if(userChoice === "rock"){
        if(computerChoice === "scissors"){
            return "rock wins";
            } else return"paper wins";}
    else if(userChoice === "paper"){
                    if(computerChoice === "rock"){
            return "paper wins";
            } else return"scissors wins";}
    else if(userChoice === "scissors"){
                    if(computerChoice === "rock"){
            return "rock wins";} 
            else return "scissors wins";}
                }


#2

You didn't call the function compare(). Just call it.


#3

Thank you man , you are a savior ^_^


#4

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