Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Well, so far I've only been able to pinpoint minor problems in your code. Since you're using strict mode, the window object's properties are not accessible globally. So you'll need to use <code>window.alert</code> or set a variable:</p> <pre><code>var alert = this.alert; // "this" being the global, window object </code></pre> <p>The first thing I noticed is that you didn't have a closing bracket to your <code>math.play</code> function declaration. I fixed that. But what the real problem you were having was that you were referencing properties of <code>mathGame</code> before they were created. For example, in the definition of <code>mathGame.play()</code>, you ran the function <code>mathGame.ui.startCountDown();</code> but <code>mathGame.ui</code> was defined in the function below the call. So I took it out the function so that it could have access to it. That was the general problem with your script.</p> <p>There was also a part where you called an object as if it were a function:</p> <pre><code>correct = (question() === guess); </code></pre> <p><code>question</code> was already defined as the return value of the function <code>mathGame.logic.getQuestion();</code> which was a string. I think you were confusing it with this:</p> <pre><code>question = mathGame.logic.getQuestion; correct = (question() === guess); // now this works </code></pre> <p>I also fixed up some things I found superfluous. If you want the entire script to be in strict mode, then create a closure over it in strict mode:</p> <pre><code>(function() { "using strict"; // everything below is in strict mode })(); </code></pre> <p>Here is the entire code:</p> <pre><code>(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 </code></pre> <p><a href="http://jsfiddle.net/gBW27/" rel="nofollow"><strong>JSFiddle Demo</strong></a></p> <p>Note that in the HTML section of the code, I took out some script files because they were non-existent in website. If you need them again, here they are:</p> <pre><code>&lt;script src="mathGame.js"&gt;&lt;/script&gt; &lt;script src="mathGame.logic.js"&gt;&lt;/script&gt; &lt;script src="mathGame.ui.js"&gt;&lt;/script&gt; &lt;script src="mathGame.play.js"&gt;&lt;/script&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload