<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
Keyboard Shortcuts
Shortcut | Action |
---|---|
ctrl + [num] | Toggle nth panel |
ctrl + 0 | Close focused panel |
ctrl + enter | Re-render output. If console visible: run JS in console |
Ctrl + l | Clear the console |
ctrl + / | Toggle comment on selected lines |
ctrl + ] | Indents selected lines |
ctrl + [ | Unindents selected lines |
tab | Code complete & Emmet expand |
ctrl + shift + L | Beautify code in active panel |
ctrl + s | Save & lock current Bin from further changes |
ctrl + shift + s | Open the share options |
ctrl + y | Archive Bin |
Complete list of JS Bin shortcuts |
JS Bin URLs
URL | Action |
---|---|
/ | Show the full rendered output. This content will update in real time as it's updated from the /edit url. |
/edit | Edit the current bin |
/watch | Follow a Code Casting session |
/embed | Create an embeddable version of the bin |
/latest | Load the very latest bin (/latest goes in place of the revision) |
/[username]/last | View the last edited bin for this user |
/[username]/last/edit | Edit the last edited bin for this user |
/[username]/last/watch | Follow the Code Casting session for the latest bin for this user |
/quiet | Remove analytics and edit button from rendered output |
.js | Load only the JavaScript for a bin |
.css | Load only the CSS for a bin |
Except for username prefixed urls, the url may start with http://jsbin.com/abc and the url fragments can be added to the url to view it differently. |