Rock, Paper, Stuck


#1


Every time I run my code, I get an error reading "Oops, try again. Make sure to call your compare function with userChoice and computerChoice as the arguments!"

Can anyone point me in the right direction or possibly correct the error in  my code? Thank you.


/*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 === "paper") {
        return "scissors wins";
    }
    else {
        return "rock wins";
    }

}

}


#2

Hi @mi_conservative

I am afraid I am not in a position just now to double check the lesson, but at a quick gander on your code, everything looks happy :slight_smile: I think all you really need is to do exactly what the error message is telling, which is call the compare function.
The sample is below if that helps, if this doesn't get you rockin' please feel free to reply back and someone will try to help as soon as they can :slight_smile:

var userChoice = prompt("Do you choose rock, paper or scissors?"); //uncomment to start the app
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 === "paper") 
        {
            return "scissors wins";
        }
        else {
            return "rock wins";
        }
    }

}

compare(userChoice, computerChoice); //this is possibly all you need, to literally call the "compare" function

#3

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