Making sense of it


#1

I just basically don't understand how this all works. Specifically steps 6 through 8.


#2

@methodrunner10875,

Please read
http://www.codecademy.com/forum_questions/559dcb4be39efe550f00006b
and concentrate on:

  • the creation of the compare function
  • the truth-table
  • the build of the IF ELSE-IF statement structure as part of the compare FUNCTION-BODY
  • the execution of the compare function (keeping in mind that the return statement is used )

#3

Ok i will go over step 6 with you completely, and tell me if you understand the specific steps you mentioned :smile::

The First Instruction in Step 6 is:

1: Inside the compare() function under the existing code, write an else if statement where the condition is choice1 === "rock".

So in our exisisting compare() function which i hope you undertand we just right an else if statement under the existing code(if statement)

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

Now Second Instruction

  1. Inside this else if statement, write an if / else statement. If choice2 === "scissors", return "rock wins". Else, return "paper wins".

Thats pretty easy to, just writing an if/else statement:

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";
                        }
                }
}

Here is a Documentation that would really help you here.


#4

Thanks, I think I get it now. Y'all are awesome!


#5

No Problem, i forgot to close a bracket at the end as @leonhard_wettengmx_n mentioned to me. FacePalm... I guess everyone makes mistakes? :smile: