8. What if choice1 is scissors?


#1

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

Code:

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

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

who will win when the inputs are scissors and paper ?


#3

I don't know :confused: i can't see what im doing wrong?


#4

if choice2 isn't rock (if condition is false) choice2 has to be paper, so then you have choice1 is scissors, and choice2 is paper, and then paper beats scissors? As @rcodeman is trying to say, you return the wrong thing


#5

Ok thank you, got it working but now i'm getting the error : Oops, try again. Make sure to call your compare function with userChoice and computerChoice as the arguments! which i have done.


#6

uhm.. no? There is no function call. You created the compare function, yes, but you never called the function. If you don't remember function calls revisit exercise in the introduction to function track


#7

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