8. What if choice1 is scissors?


#1



Oops, try again. Your code returned 'paper wins' instead of 'undefined' when the inputs are scissors and paper


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';
    }
}
else if(choice1 === 'scissors') {
    
    if(choice2 === 'rock') {
        return 'rock wins';
    }
    else {
        return 'paper wins';
    }
}
}


#2

okay, so here:

else if(choice1 === 'scissors') {
    
    if(choice2 === 'rock') {
        return 'rock wins';
    }
    else {
        return 'paper wins';
    }
}
}

if the user picks scissors and the computer picks paper, then paper beats scissors?


#3

ok amended the error so scissors win. I now receive the following:

Make sure to call your compare function with userChoice and computerChoice as the arguments!

What is confusing me is the prompt function that appears when I click run. Do I input userChoice and computerChoice using console.log?


#4

you build a function (called compare) which checks who won. But function only executes when called, so now you have to add a function call to execute the function and determine the winner.

your function has two parameters, so you need to supply 2 arguments function calls

in track 3 (called function) you learned about function and function call, can you remember it?


#5

am i going in the right direction with this:

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


#6

you can always revisit the introduction to function track.

now you are logging computerChoice and userChoice, but you need to call the compare function. here you build the compare function:

var compare = function (choice1, choice2)

how do you call a function?


#7

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