Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Apr 12th, 2012  |  syntax: jQuery  |  size: 2.73 KB  |  hits: 28  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
This paste has a previous version, view the difference. Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta name="keywords" content="photography,art,design,addison,photo"/>
  5. <meta name="description" content="I take photos."/>
  6. <meta charset="utf-8" />
  7. <title>Addison Bean | Photography & Design</title>
  8. <link rel="stylesheet" type="text/css" href="css/abd.css"/>
  9. <link rel="stylesheet" type="text/css" href="css/gsquares.dark.css"/>
  10. <!--[if IE]>
  11. <style type="text/css>
  12. li.menu {
  13.         font-family:Trebuchet MS, Helvetica, sans-serif;
  14. }
  15. </style>
  16. <![endif]-->
  17. <!--favicon won't show up-->
  18. <link rel="Shortcut Icon" href="favicon.ico"/>
  19. <style type="text/css">
  20.         #scores {
  21.                 color: #fff;
  22.         }
  23. </style>
  24. </head>
  25. <body>
  26. <div id="container"><br />
  27.         <div id="scores">
  28.                 <div id="player1_score"><p>Player 1: 0</p></div>
  29.                 <div id="player2_score"><p>Player 2: 0</p></div>
  30.         </div>
  31.         <button id="player1_go">Player 1</button>
  32.         <button id="player2_go">Player 2</button>
  33. </div>
  34. <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script> 
  35. <script type="text/javascript">
  36.        
  37.         $(document).ready(function(){
  38.                
  39.                 GAMESTATE = {
  40.                         answer: Math.floor(Math.random()*11),
  41.                         player1_score: 0,
  42.                         player2_score: 0
  43.                 }
  44.                
  45.                
  46.                 console.log(GAMESTATE.answer);
  47.                 $('#player1_go').click(function(event){
  48.                                         console.log(GAMESTATE.answer);
  49.                         var player1_answer = prompt('Guess a number between 0 and 10.','');
  50.                         if(player1_answer == GAMESTATE.answer){
  51.                                 alert('right on dude!');
  52.                                 GAMESTATE.player1_score += 1;
  53.                                 updateScores();
  54.                         } else {
  55.                                 alert('you got it wrong bro, the answer is: ' + GAMESTATE.answer);
  56.                         }
  57.                        
  58.                         GAMESTATE.answer =  Math.floor(Math.random()*11),
  59.                         event.preventDefault();
  60.                 });
  61.                
  62.                 $('#player2_go').click(function(event){
  63.                         console.log(GAMESTATE.answer);
  64.                         var player1_answer = prompt('PLAYER     1: Guess a number between 0 and 10.','');
  65.                         var player2_answer = prompt('PLAYER     2: Guess a number between 0 and 10.','');
  66.                        
  67.                         if(player1_answer == GAMESTATE.answer){
  68.                                 alert('PLAYER 1: right on dude!');
  69.                                 GAMESTATE.player1_score += 1;
  70.                                 updateScores();
  71.                         } else {
  72.                                 alert('PLAYER 1: you got it wrong bro, the answer is: ' + GAMESTATE.answer);
  73.                         }
  74.                        
  75.                         if(player2_answer == GAMESTATE.answer){
  76.                                 alert('PLAYER 2: right on dude!');
  77.                                 GAMESTATE.player2_score += 1;
  78.                                 updateScores();
  79.                         } else {
  80.                                 alert('PLAYER 2: you got it wrong bro, the answer is: ' + GAMESTATE.answer);
  81.                         }
  82.                        
  83.                         GAMESTATE.answer =  Math.floor(Math.random()*11),
  84.                         event.preventDefault();
  85.                 });
  86.                
  87.                
  88.                 updateScores = function(){
  89.                         $('#player1_score').html('<p>Player 1: ' + GAMESTATE.player1_score + '</p>');
  90.                         $('#player2_score').html('<p>Player 2: ' + GAMESTATE.player2_score + '</p>');
  91.                 }
  92.                
  93.                
  94.         });
  95. </script>
  96. </body>
  97. </html>