== Build "Rock, Paper, Scissors" ==
Tutorial 6#
You're doing great! Now we consider the other scenarios. Let's break the problem down a little. What if
a. if
b. if
Problem:
Let's code our outline from above:
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);
Tutorial 6#
What if choice1 is rock?
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:
- Inside the
compare()function under the existing code, write anelse ifstatement where the condition ischoice1 === "rock". - Inside this
else ifstatement, write anif/elsestatement. Ifchoice2 === "scissors", return"rock wins". Else, return"paper wins".
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