8. What if choice1 is scissors?


At this stage we are told in the instructions to call the functions userChoice and computerChoice, but we are not told what to call them. I have tried a few possibilities but they haven't worked.

userChoice("what am I called?")


no, you are told to call the compare() function which you build over the past few exercise, and supply userChoice and computerChoice as arguments


I've tried this too because I saw that others in the forum had done this. So I huess the problem is something else that I can't work out...


can you provide your full code + how you have done this? This is impossible for me to guess, and a mistake is easily made


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


What confuses me the most is that at this stage I haven't really changed anything, all I have done is to call the functions


you also added what if choice1 is scissors:

else (choice1 === "scissors")

else can't have a condition, use either else if or remove the condition from else

I would choice the first of the two options


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