8. What if choice1 is scissors?


#1


What did I do wrong?



Your code returned 'Rock wins' instead of 'undefined' when the inputs are scissors and paper


Replace this line with your 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);

function compare (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";
            }
        }
        if (userChoice==="paper") {
            if (computerChoice==="rock") {
                return "Paper wins";
            }
            else {
                return "Scissors win";
            }
        }
        if (userChoice==="scissors") {
            if (computerChoice="rock") {
                return "Rock wins";
            }
            else {
                return "Paper wins";
            }
        }
    }
}


#2

Exercise 5/9 states that we're to use the parameters choice1 and choice2 instead of userChoice and computerChoice.

Instead of using those as the parameters, you call on them later on when you call on the function.


#3

i changed the function arguments back to choice1 and choice2, but still get this message: "Your code returned 'Rock wins' instead of 'undefined' when the inputs are scissors and paper".
this is my 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);

function compare (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";
}
}
if (choice1==="paper") {
if (choice2==="rock") {
return "Paper wins";
}
else {
return "Scissors win";
}
}
if (choice1==="scissors") {
if (choice2="rock") {
return "Rock wins";
}
else {
return "Scissors wins";
}
}
}
}

compare (userChoice, computerChoice);


#4

Check this block for any issues

If you still can't figure it out,

I'm pretty sure that your issue is in t fact that paper doesn't beat scissors


#5

I changed that too, along with the function parameters. Check the last code I posted :smiley:


#6

Right here, you're missing a few equal marks.


#7

thanks a loooot, I didn't really pay attention to that ...


#8

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