Created
January 8, 2014 15:09
-
-
Save emohamed/8318173 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <!doctype html> | |
| <html lang="en"> | |
| <head> | |
| <meta charset="UTF-8"> | |
| <title>Rock - Scissors - Paper</title> | |
| <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.js"></script> | |
| <script> | |
| "use strict" | |
| $(function() { | |
| // $('button').click(function() { | |
| // var user_choice = $(this).text().toLowerCase(); | |
| // var choices = ["rock", "paper", "scissors"]; | |
| // var computer_choice = choices[Math.floor(Math.random() * choices.length)]; | |
| // var winner; | |
| // var message; | |
| // if (user_choice == computer_choice) { | |
| // alert("Draw. "); | |
| // return; | |
| // } else if (user_choice == "paper" && computer_choice == "scissors") { | |
| // winner = "computer"; | |
| // } else if (user_choice == "paper" && computer_choice == "rock") { | |
| // winner = "user"; | |
| // } else if (user_choice == "scissors" && computer_choice == "rock") { | |
| // winner = "computer"; | |
| // } else if (user_choice == "scissors" && computer_choice == "paper") { | |
| // winner = "user"; | |
| // } else if (user_choice == "rock" && computer_choice == "paper") { | |
| // winner = "computer"; | |
| // } else if (user_choice == "rock" && computer_choice == "scissors") { | |
| // winner = "user"; | |
| // } | |
| // message = "You picked the " + user_choice + " and the computer picked the " + computer_choice + ". "; | |
| // if (winner == "user") { | |
| // message += "You have won this one! "; | |
| // } else { | |
| // message += "You have lost this one! "; | |
| // } | |
| // alert(message); | |
| // }); | |
| // | |
| // | |
| /******************************************************/ | |
| $('button').click(function() { | |
| var choices = ["rock", "paper", "scissors"]; | |
| var user_choice = $(this).text().toLowerCase(); | |
| var computer_choice = choices[Math.floor(Math.random() * choices.length)]; | |
| var game_win_rules = { | |
| // winner: loser | |
| rock: "scissors", | |
| paper: "rock", | |
| scissors: "paper" | |
| }; | |
| var message; | |
| if (user_choice == computer_choice) { | |
| alert("Draw. "); | |
| return; | |
| } | |
| message = "You picked the " + user_choice + " and the computer picked the " + computer_choice + ". "; | |
| if (game_win_rules[user_choice] == computer_choice) { | |
| message += "You have won this one! "; | |
| } else { | |
| message += "You have lost this one! "; | |
| } | |
| alert(message); | |
| }); | |
| }) | |
| </script> | |
| </head> | |
| <body> | |
| <div class="shell"> | |
| <p>Pick your choice:</p> | |
| <ul> | |
| <li> | |
| <button>Rock</button> | |
| </li> | |
| <li> | |
| <button>Scissors</button> | |
| </li> | |
| <li> | |
| <button>Paper</button> | |
| </li> | |
| </ul> | |
| </div> | |
| </body> | |
| </html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment