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 8870345
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T17:42:11+00:00 2026-06-14T17:42:11+00:00

In my program I have global variables at the top that are used by

  • 0

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…

http://jsfiddle.net/sYDs4/1/

  • 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-14T17:42:12+00:00Added an answer on June 14, 2026 at 5:42 pm

    Here are a few comments that do not fit in comments…

       if (populationNumber >= 6) {
            var populationNumber = 6;
        }
        if (completionNumber >= 6) {
            var completionNumber = 6;
        }
    

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

    function nextButton() {
        //Next question click event
        $('td').removeClass('highlight-problem');
        var r = randomWord;
        while (r == randomWord) {
            randomWord = Math.floor(Math.random() * (listOfWords.length));
        }
    

    This assigns a number to randomWord which is used as an array in other places but as a number in this function. The same goes for the closeButton function too.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have learnt that memory for global variables are allocated at program startup whereas
Suppose I have a program that initializes a global variable for use by threads,
I have a program that I'm working on that register global hotkeys I would
In an C program, I need to re-initialize all global variables as they where
I'm trying to understand how global variables and functions work in C. My program
I have a big list of global variables that each have their own setup
I have a jsp application (using Spring) that uses a couple of global variables.
Hi I have a program written in C. I have global variables, arrays, dynamic
I have some global variables (classes) that as I understand have created before main()
I want to use some global variables in my program. Do we have anything

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.