Can someone please explain what is going on here?


There are NO ERRORS, but could someone please explain the working ? I mean how does the compare function help ? The parameters we have taken are choice1 and choice2 and we haven't even equated them with userChoice and computerChoice . so even if I give "paper" and "scissors" as input parameters for the compare function, what exactly is the use of userChoice ?... Even if I gave userChoice as "rock" The program will still compare the parameters i.e. "paper" and "scissors" and tell me that "scissors" wins.

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) {
        return "The result is a tie!";
    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";


Continuing the discussion from 8. What if choice1 is scissors:


lets do a simple example:

w = 3
z = 4
var example = function(x,y){

you pass the variable w and z into the function when calling it, now inside the function this variable are x and z (3 and 4 will be printed), you can do same for you computer and userchoice:


now, userChoice will be choice1, and computerChoice will be choice2.


this is a rather important step, otherwise it wouldn't function properly.

Yea, passing "paper" and "scissors" would cause confusion. The function call is included in this exercise, step 3 of the instructions


Cool ,thanks. Actually the instruction was already given to pass userChoice and computerChoice as parameters.. I didn't pay attention. Haha.. :confused: :stuck_out_tongue: