Saturday, 28 June 2014

== Build "Rock, Paper, Scissors" ==
Tutorial 6#
What if choice1 is rock?
You're doing great! Now we consider the other scenarios. Let's break the problem down a little. What if choice1 is "rock"? Given choice1 is "rock",
a. if choice2 === "scissors", then "rock" wins.
b. if choice2 === "paper", then "paper" wins.

Problem:
Let's code our outline from above:
  1. Inside the compare() function under the existing code, write an else if statement where the condition is choice1 === "rock".
  2. Inside this else if statement, write an if / else statement. If choice2 === "scissors", return "rock wins". Else, return "paper wins".
Solve:
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";
            }
        }
};
compare("rock",1);

No comments:

Post a Comment