Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>JS Bin</title>
</head>
<body>
  <h1>Rock, Paper, Scissors</h1>
  <p>Folow the steps to finish the game.  Some parts have been started for you.</p>
  <p>Remember "//" is a comment in the code and will do nothing</p>
  <p>When you see "//todo:" in the code, you need to add more code</p>
  <ol>
    <li>Ask the user for thier choice
      <pre>var usersChoice = prompt("Do you choose rock, paper or scissors?");</pre></li>
    <li>Get a random computer choice by calling the GetRandomChoice() function and saving it to the "computerChoice" variable.
      <pre>var computerChoice = GetRandomChoice();
    </pre>
    </li>
    <li>Display the computer's choice. Remember to use the alert command.  <pre>alert("The computer chooses " + computerChoice);</pre>
    </li>
    <li>Find the winner and save the results as "results" using the GetResults() function.
     <pre>var results = GetResults(usersChoice, computerChoice);</pre>
    </li>
    <li>Complete the GetResults() function. Only a few possible situations have been completed.
    </li>
    
    <li>Display the winner
     <pre>alert(results);
    </pre>
    </li>
    <li>Run the game</li>
  </ol>
</body>
</html>
 
//todo: ask the user for thier choice
//todo: call GetRandomChoice() to get a random computer choice
//todo: display the computers choice
//todo: find the winner
//todo: display the winner
function GetRandomChoice()
{
  //randomNumber will equal 1, 2, or 3
  var randomNumber = Math.round((Math.random()*2) + 1);
  
  if(randomNumber == 1)
  {
    return "paper";
  }
  if(randomNumber == 2)
  {
    return "rock";
  }
  if(randomNumber == 3)
  {
    return "scissors";
  }
}
function GetResults(usersChoice, computersChoice)
{
  if(usersChoice == "rock" && computersChoice == "rock")
  {
    return "You have tied with the mighty computer.";
  }
  if(usersChoice == "rock" && computersChoice == "paper")
  {
    return "The computer has covered your rock, and therefore destroyed you.";
  }
  if(usersChoice == "rock" && computersChoice == "scissors")
  {
    return "You have destroyed the mighty computer's scissors!";
  }
  
  //todo: finish the logic for when the user selects paper
  
  //todo: finish the logic for when the user selects scissors
  
  return "?";
}
Output

You can jump to the latest bin by adding /latest to your URL

Dismiss x
public
Bin info
jamesfdickinsonpro
0viewers