Advertisement
Guest User

Untitled

a guest
Sep 4th, 2015
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.96 KB | None | 0 0
  1. $(document).ready(function() {
  2. var totalAmount = 0;
  3. var compAmount = 0;
  4. var compGen = function() {
  5. compAmount = (Math.floor(Math.random() * 11) * 2) + 1;
  6. while (compAmount <= 10) {
  7. compAmount += Math.ceil(Math.random() * 11);
  8. }
  9. };
  10.  
  11. var bustCheck = function() {
  12. if (totalAmount > 21) {
  13. $('#draw').hide();
  14. $('#results').show();
  15. $('#results').text('You busted!');
  16. }
  17. }
  18.  
  19. var blackjackCheck = function() {
  20. if (totalAmount === 21) {
  21. $('#draw').hide();
  22. $('#results').show();
  23. $('#results').text("Blackjack! You win!");
  24. }
  25. }
  26.  
  27. var compareScore = function() {
  28. if (totalAmount > compAmount) {
  29. $('#results').text("Congrats! You win!");
  30. }
  31. else if (totalAmount < compAmount) {
  32. $('#results').text("I'm sorry, looks like you lose.")
  33. }
  34. else {
  35. $('#results').text("It's a tie. How boring.")
  36. }
  37. };
  38.  
  39. var restart = function() {
  40. $('#draw').show();
  41. $('#direct').hide();
  42. $('#results').hide();
  43. $('#userscore').text(0);
  44. $('#compscore').text("?");
  45. totalAmount = 0;
  46. compAmount = 0;
  47. };
  48.  
  49. $('#yes').click(function() {
  50. var drawAmount = Math.ceil(Math.random() * 11)
  51. totalAmount += drawAmount;
  52. $('#userscore').text(totalAmount);
  53. bustCheck();
  54. blackjackCheck();
  55. })
  56.  
  57. $('#no').click(function() {
  58. compGen();
  59. $('#compscore').text(compAmount);
  60. $('#draw').hide();
  61. $('#results').show();
  62. compareScore();
  63. })
  64.  
  65. $('#directions').click(function() {
  66. $('#direct').toggle("slow");
  67. })
  68.  
  69. $('#newgame').click(function() {
  70. restart();
  71. })
  72. restart();
  73. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement