How to simplify a set of vars?
var q1 = 0;
var q2 = 0;
var q3 = 0;
var q4 = 0;
var q5 = 0;
var q6 = 0;
var q7 = 0;
var q8 = 0;
var q9 = 0;
var q10 = 0;
var counter = 0;
or like this?
var q1 = 0, q2 = 0, q3 = 0, q4 = 0, q5 = 0, q6 = 0, q7 = 0, q8 = 0, q9 = 0, q10 = 0, counter = 0;
Is there any way around?
var q=[0,0,0,0,0,0,0,0,0,0]q1throughq10all instances of essentially the same thing? If so, you should definitely use an array. Here's a simple example: suppose you have a carton of 12 eggs, and you need to write some code that deals with each egg in some way. Would it make sense to have twelve individual unrelated variablesegg1throughegg12? Or would it be better to be able to deal with each egg just like the others? It's probably the latter, so an array is what you're looking for.