0

I have a typing web game written using JS. The JS contains all the necessary definition and algorithm of the game. There is a global variable called game_mode. By altering this variable to either 0, 1 or 2, I can load different game modes on the webpage. My difficulty is, I can't figure out a way where I can edit game_mode before I load the JS content using HTML. If I load the JS, the JS already starts running and thus the game starts, using the game_mode hard-coded. Is there anyway to do so?

1
  • Put the variable in the page itself instead of in the script file. Commented Apr 26, 2015 at 16:44

1 Answer 1

2

Take all your Javascript code that you have written and put into a file, example game.js. In your HTML you can import/reference the Javascript. Before referencing it set the variable game_mode to the desired value.

See below.

index.html

<script>
    var game_mode = 2;
</script>
<script src="/game.js"> </script>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.