In my program I have global variables at the top that are used by various functions in the game. When they are called sometimes they come up as undefined in the console. I have been playing around for so long with it but cannot seem to find the source of the problem. Is it because they are arrays, or is there another reason?
var randomWord = [];
var listOfWords = [];
var gridSize = [];
var populationNumber = [];
var completionNumber = [];
var attemptNumber = [];
Here is a fiddle with the script in…
Here are a few comments that do not fit in comments…
should not be done in JS, this is dangerous as you create a local variable with the same name as the global one. Without even mentioning that you assign a number to a variable supposed to be an array (the global one).
This assigns a number to
randomWordwhich is used as an array in other places but as a number in this function. The same goes for thecloseButtonfunction too.