Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- mathGame.logic = (function() {
- "use strict";
- var createQuestion, getQuestion;
- createQuestion = function() {
- var tal1, tal2;
- tal1 = Math.ceil(Math.random() * 10);
- tal2 = Math.ceil(Math.random() * 10);
- return {
- tal1: tal1,
- tal2: tal2,
- result: function() {
- return tal1 + tal2;
- }
- };
- };
- getQuestion = function() {
- return createQuestion();
- };
- return {
- getQuestion: getQuestion
- };
- }());
- mathGame.play = function() {
- "use strict";
- var question, guess, answer, correct, questionGuess;
- // Starts game for user
- mathGame.ui.startCountDown();
- // Starts the timer in .logic
- // mathGame.logic.startCountDown();
- // Get random math
- question = mathGame.logic.getQuestion();
- // Send random math to User
- questionGuess = mathGame.ui.askMathQuestion(question.tal1, question.tal2);
- // The users guess
- guess = mathGame.ui.returnMathGuess;
- // See if the question is the same as the guess
- correct = (question() === guess);
- // Show the user how it went
- mathGame.ui.showResult(correct, guess, question);
- ##Mathgame.ui.js##
- mathGame.ui = {
- startCountDown: function() {
- "use strict";
- // Visa ready set go
- alert("READY");
- alert("SET");
- alert("GO");
- },
- askMathQuestion: function() {
- "use strict";
- prompt("askMathQuestion");
- //shows a math question to user
- // return Number(prompt(value1 + symbol + value2));
- // e.g. value1 = 12
- // value2 = 13
- // symbol = "+"
- // 12 + 13
- // return user guess
- },
- returnMathGuess: function() {
- "use strict";
- },
- showResult: function() {
- "use strict";
- }
- };
- var alert = this.alert; // "this" being the global, window object
- correct = (question() === guess);
- question = mathGame.logic.getQuestion;
- correct = (question() === guess); // now this works
- (function() {
- "using strict";
- // everything below is in strict mode
- })();
- (function() {
- "using strict";
- var mathGame = {},
- alert = this.alert,
- prompt = this.prompt;
- mathGame.play = function() {
- var question, guess, answer, correct, questionGuess;
- // Starts game for user
- mathGame.ui.startCountDown();
- // Starts the timer in .logic
- // mathGame.logic.startCountDown();
- // Get random math
- mathGame.logic = (function() {
- var createQuestion, getQuestion;
- createQuestion = function() {
- var tal1, tal2;
- tal1 = Math.ceil(Math.random() * 10);
- tal2 = Math.ceil(Math.random() * 10);
- return {
- tal1: tal1,
- tal2: tal2,
- result: function() {
- return tal1 + tal2;
- }
- };
- };
- getQuestion = function() {
- return createQuestion();
- };
- return {
- getQuestion: getQuestion
- };
- }());
- question = mathGame.logic.getQuestion();
- // Send random math to User
- questionGuess = mathGame.ui.askMathQuestion(question.tal1, question.tal2);
- // The users guess
- guess = mathGame.ui.returnMathGuess;
- // See if the question is the same as the guess
- correct = (question === guess);
- // Show the user how it went
- mathGame.ui.showResult(correct, guess, question);
- };
- mathGame.ui = {
- startCountDown: function() {
- // Visa ready set go
- alert("READY");
- alert("SET");
- alert("GO");
- },
- askMathQuestion: function() {
- prompt("askMathQuestion");
- //shows a math question to user
- // return Number(prompt(value1 + symbol + value2));
- // e.g. value1 = 12
- // value2 = 13
- // symbol = "+"
- // 12 + 13
- // return user guess
- },
- returnMathGuess: function() {},
- showResult: function() {}
- };
- mathGame.play();
- }).call(this); // global object
- <script src="mathGame.js"></script>
- <script src="mathGame.logic.js"></script>
- <script src="mathGame.ui.js"></script>
- <script src="mathGame.play.js"></script>
Add Comment
Please, Sign In to add comment