Javascript: Typeerror Variable Is Undefined
Solution 1:
This probably means that control + j
is greater than or equal to the length of the array rbuttons
. There's no such array element as rbuttons[control + j]
.
You should learn how to use the JavaScript debugger in your favorite browsers! Debuggers are great. They let you watch this code run, line by line, as fast or as slow as you want, and watch how the value of control
changes as you go.
You’ll watch it, and you’ll think “Oh! That line of code is wrong!”
Solution 2:
You're looping through rbuttons.length
times, but in each loop you're adding 2 to control
. Using control
to index your array, you're going to run past the end.
Solution 3:
Does the index specified by control + j exist in the array? i.e: If that evaluates to 4, is there at least 5 items in the array?
Also, you should be using var i, var j, etc inside your for loop. Without it your variables are leaking into the scope this code is executed in (most likely the global scope, and that's not good) :)
Post a Comment for "Javascript: Typeerror Variable Is Undefined"