Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8599879
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T01:29:34+00:00 2026-06-12T01:29:34+00:00

I have a school project where we are making a small JavaScript game without

  • 0

I have a school project where we are making a small JavaScript game without a UI; this means we can only use prompt, alert or other popup scripts.

The game should work, at least it did before i broke it apart with the module. It’s a simple math game where user gets random +, questions and has to answer them correctly

The problem(s)

I don’t seem to be able to get any prompts to the user. I’m also having trouble debugging this in chrome dev tools, can you see anything that seems wrong right away? Thankful for any help at all 🙂

Heres the JSfiddle

http://jsfiddle.net/vuTGa/1/

This is our code, I only posted the vital parts – I left out the index.html and Mathgame.js because they seem to work perfect and also they do not contain a lot of code.

MathGame.logic.js

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.js

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";
        }
    };
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T01:29:36+00:00Added an answer on June 12, 2026 at 1:29 am

    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 window.alert or set a variable:

    var alert = this.alert; // "this" being the global, window object
    

    The first thing I noticed is that you didn’t have a closing bracket to your math.play function declaration. I fixed that. But what the real problem you were having was that you were referencing properties of mathGame before they were created. For example, in the definition of mathGame.play(), you ran the function mathGame.ui.startCountDown(); but mathGame.ui 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.

    There was also a part where you called an object as if it were a function:

    correct = (question() === guess);
    

    question was already defined as the return value of the function mathGame.logic.getQuestion(); which was a string. I think you were confusing it with this:

    question = mathGame.logic.getQuestion;
    
    correct = (question() === guess); // now this works
    

    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:

    (function() {
        "using strict";
        // everything below is in strict mode
    })();
    

    Here is the entire 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
    

    JSFiddle Demo

    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:

    <script src="mathGame.js"></script>
    <script src="mathGame.logic.js"></script>
    <script src="mathGame.ui.js"></script>
    <script src="mathGame.play.js"></script>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm making a small game for a school project, and basically there are 20
I have the mission to make a small game for a school project. Pictures
I have this school project I'm making, where I need to make my code
Im making a table generator as a school project. In MySQL I have 3
for a school project i'm making a jigsaw puzzle out of javascript and jquery.
I am making a Grails application for a school project and I have run
I have a small school management project. There are a few thousand records per
I have to use idlj for my school project but in my idl files
I have a school project that i think i can do with the concept
I have to to game for my school project. I have a little problem

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.