What is wrong here?


#1

what is wrong here??

var compare = function(choice1, choice2) {
    if(choice1 === choice2) {
        return("The result is a tie!")
    }
    else if(choice2 === "scissors") {
        return("rock wins")
    } else {
        return("paper wins")
    } else if(choice1 === "paper") {
        if(choice2 === "rock") {
            return("paper wins")
        } else {
            return("scissor wins")
        }
    }
}

7/9 rock paper scissors help please
#2

In this exercise, your else ifs should have choice1 in the condition followed by a nested if/else code block.

This section is correct. Follow this as a guide and you will come to a solution.


#4

thank you for the help. but something is still wrong... :confused:

var compare = function(choice1, choice2) {
    if(choice1 === choice2) {
        return("The result is a tie!")
    } else if(choice1 === "scissors") {
        return("rock wins")
    } else {
        return("paper wins")
    } else if(choice1 === "paper") {
        if(choice2 === "rock") {
            return("paper wins")
        } else {
            return("scissor wins")
        }
    }
};

#5

You corrected choice2 to choice1 in your else if condition but where is your nested if/else? Also, I don't think you need parentheses in your return statements.


#6

the problem can't be on the first part. that was ex.6 the bottom part is ex.7...


#7

can you please post the correct code. this is getting on my nerves.
i have been on this exercise for the past 3 hours!


#8

If you all you want is to copy an answer, you can find it on the forums or use google. I'm trying to help you debug your own script, one error at a time.

Javascript runs from top to bottom, evaluating and executing as conditions are triggered or passed over. If you don't write the program correctly, it won't run.

You are being given exercises, step by step, to write a game. As you add options to the game, your code must be altered to incorporate the new options.

Choice1 === "rock" will be another option for this game. You will have to alter your code again. For now, let's focus on your else if for choice1 === scissors. Or not. Your choice.


#9

I completely understand, but right now I am just getting pissed off with this exercise!!


#10

You can do it!

Your code should look something like this for each choice1:

else if (choice1 condition){
if (choice2 condition){
return code;
} else {
return code;
}
}


#11

wrote the whole code again... i just can see the problem!!

var compare = function(choice1, choice2) {
    if(choice1 === choice2) {
        return"The result is a tie";
    } else if(choice2 === "scissors") {
        if(choice1 === "rock") {
            return"rock wins";
        }
        else {
            return"paper wins";
        }
    }
    else if(choice1 === "paper") {
        if(choice2 === "rock" {
            return"paper wins";
        }
        else {
            return"scissor wins");
        }
    }
};

#12

Great syntax! However, your else if conditions should have choice1 and your if conditions should have choice2. Also, your return code should reflect the rules of the paper, rock, scissors game. In your else code here, paper beats scissors.


#13

Thank you for your time!!!

Fixed! Hooray!!

:smiley: :smiley:


#14

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