Guest User

Untitled

a guest
Jan 18th, 2019
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.49 KB | None | 0 0
  1. mathGame.logic = (function() {
  2. "use strict";
  3. var createQuestion, getQuestion;
  4. createQuestion = function() {
  5. var tal1, tal2;
  6. tal1 = Math.ceil(Math.random() * 10);
  7. tal2 = Math.ceil(Math.random() * 10);
  8. return {
  9. tal1: tal1,
  10. tal2: tal2,
  11. result: function() {
  12. return tal1 + tal2;
  13. }
  14. };
  15. };
  16. getQuestion = function() {
  17. return createQuestion();
  18. };
  19. return {
  20. getQuestion: getQuestion
  21. };
  22. }());
  23.  
  24. mathGame.play = function() {
  25. "use strict";
  26. var question, guess, answer, correct, questionGuess;
  27. // Starts game for user
  28. mathGame.ui.startCountDown();
  29. // Starts the timer in .logic
  30. // mathGame.logic.startCountDown();
  31. // Get random math
  32. question = mathGame.logic.getQuestion();
  33. // Send random math to User
  34. questionGuess = mathGame.ui.askMathQuestion(question.tal1, question.tal2);
  35. // The users guess
  36. guess = mathGame.ui.returnMathGuess;
  37. // See if the question is the same as the guess
  38. correct = (question() === guess);
  39. // Show the user how it went
  40. mathGame.ui.showResult(correct, guess, question);
  41.  
  42.  
  43.  
  44. ##Mathgame.ui.js##
  45. mathGame.ui = {
  46.  
  47. startCountDown: function() {
  48. "use strict";
  49. // Visa ready set go
  50. alert("READY");
  51. alert("SET");
  52. alert("GO");
  53. },
  54. askMathQuestion: function() {
  55. "use strict";
  56. prompt("askMathQuestion");
  57. //shows a math question to user
  58. // return Number(prompt(value1 + symbol + value2));
  59. // e.g. value1 = 12
  60. // value2 = 13
  61. // symbol = "+"
  62. // 12 + 13
  63. // return user guess
  64. },
  65. returnMathGuess: function() {
  66. "use strict";
  67. },
  68. showResult: function() {
  69. "use strict";
  70. }
  71. };
  72.  
  73. var alert = this.alert; // "this" being the global, window object
  74.  
  75. correct = (question() === guess);
  76.  
  77. question = mathGame.logic.getQuestion;
  78.  
  79. correct = (question() === guess); // now this works
  80.  
  81. (function() {
  82. "using strict";
  83. // everything below is in strict mode
  84. })();
  85.  
  86. (function() {
  87. "using strict";
  88. var mathGame = {},
  89. alert = this.alert,
  90. prompt = this.prompt;
  91.  
  92. mathGame.play = function() {
  93. var question, guess, answer, correct, questionGuess;
  94. // Starts game for user
  95. mathGame.ui.startCountDown();
  96. // Starts the timer in .logic
  97. // mathGame.logic.startCountDown();
  98. // Get random math
  99. mathGame.logic = (function() {
  100. var createQuestion, getQuestion;
  101. createQuestion = function() {
  102. var tal1, tal2;
  103. tal1 = Math.ceil(Math.random() * 10);
  104. tal2 = Math.ceil(Math.random() * 10);
  105. return {
  106. tal1: tal1,
  107. tal2: tal2,
  108. result: function() {
  109. return tal1 + tal2;
  110. }
  111. };
  112. };
  113. getQuestion = function() {
  114. return createQuestion();
  115. };
  116. return {
  117. getQuestion: getQuestion
  118. };
  119. }());
  120.  
  121. question = mathGame.logic.getQuestion();
  122. // Send random math to User
  123. questionGuess = mathGame.ui.askMathQuestion(question.tal1, question.tal2);
  124. // The users guess
  125. guess = mathGame.ui.returnMathGuess;
  126. // See if the question is the same as the guess
  127. correct = (question === guess);
  128. // Show the user how it went
  129. mathGame.ui.showResult(correct, guess, question);
  130. };
  131.  
  132. mathGame.ui = {
  133.  
  134. startCountDown: function() {
  135. // Visa ready set go
  136. alert("READY");
  137. alert("SET");
  138. alert("GO");
  139. },
  140. askMathQuestion: function() {
  141. prompt("askMathQuestion");
  142. //shows a math question to user
  143. // return Number(prompt(value1 + symbol + value2));
  144. // e.g. value1 = 12
  145. // value2 = 13
  146. // symbol = "+"
  147. // 12 + 13
  148. // return user guess
  149. },
  150. returnMathGuess: function() {},
  151. showResult: function() {}
  152.  
  153. };
  154. mathGame.play();
  155. }).call(this); // global object
  156.  
  157. <script src="mathGame.js"></script>
  158. <script src="mathGame.logic.js"></script>
  159. <script src="mathGame.ui.js"></script>
  160. <script src="mathGame.play.js"></script>
Add Comment
Please, Sign In to add comment