Saturday, 28 June 2014

== Build "Rock, Paper, Scissors" ==
Computer Choice: Part 2
We have computerChoice but it now equals a random number between 0 and 1. We need to somehow translate this random number into a random choice of rock, paper, or scissors. How do we do this?!
 Problem:
  1. If computerChoice is between 0 and 0.33, make computerChoice equal to "rock".
  2. If computerChoice is between 0.34 and 0.66, make computerChoice equal to "paper".
  3. If computerChoice is between 0.67 and 1, make computerChoice equal to "scissors".
Solution:
var computerChoice= Math.random();
if(0.33<computerChoice < 0)
{
 computerChoice= "rock";
}
else if(0.64<computerChoice < 0.34)
{
 computerChoice= "paper";
}else(0.67<computerChoice < 1)
{
 computerChoice= "scissors";
}

No comments:

Post a Comment