Call your function and pass in userChoice and computerChoice as your two arguments


#1

I am unable to understand Build "Rock,paper and scissors" exercise
Please Help


#2

Could you be a bit more descriptive about what gives you trouble?


#3

Instructions
Under your old code, use the same structure as the past two exercises and finish off your function.
We need to use the variables userChoice and computerChoice. Uncomment the first lines of the code by deleting /* on line 1 and */ on line 9, the variables are now active and can be called.
Call your function and pass in userChoice and computerChoice as your two arguments.
Press Save & Submit Code and your game should work! Congratulations!

THESE INSTRUCTION I AM UNABLE TO UNDERSTAND


#4

And what does your code look like so far?
Or do you have a problem to call the function?

Spoiler

console.log(compare(userChoice,computerChoice));

But wasn't that introduced the lesson before?


#5

Hi, you seem like you know what's up. I can't find my own problem anywhere.

I have called compare(userChoice, computerChoice) and i have even passed it to console as in your spoiler but nothing that resembles that the program has made a comparison appears. I've even switched all the 'return's for console.log and that makes no difference.
i simply can't get my if/elses to print.

Cheers


#6

Well as you're not the OP I guess it would make much sense if you'd post your code alongside the exercise number in a new thread. As from without seeing the code it is pretty much impossible to say what is wrong with your code.


#7

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("User: " + userChoice);
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";
        }
    }
    else if(choice1 === "scissors") {
        if(choice2 === "rock") {
           return "rock wins";
        }
        else {
            return "scissors wins";
        }
    }
    compare(userChoice, computerChoice);
    
};

Hi, yeah you're right. Unless I'm just being completely blind.