this is my first javascript project and I'm having trouble passing a variable into a function.
Here is the relevant section from my "global variables"
var timesran = []; for (var x= 0; x<38; x++){ timesran[x] = 0; } Below is the first function that is trying to pass x into the function so that I can have the results stored in different arrays
function happytimes(){ for (var x= 0; x < 38; x++){ switch (x){ case 0: if (shouldiFlip[x]){ randomizer(x); //input that we want to feed into the function x++; } } (please note: I have stripped the rest of the case1-38 from the excerpt for clarity, all the other cases look the same, and have the same output - the rando function is working in each different function of the randomizer function though as it is getting new output)
Following is the randomizer function
function randomizer(a){ if (startrunning){ var rando = []; rando = Math.floor(Math.random()*4+1); timestorun[a] = rando[a]; pos[a] = 0; console.log("hi there you are in new run now"+pos[a]+rando+timestorun[a]); } else{ pos[a] = pos[a] + 1; if (pos[a] >156){ pos[a] = 0; } if (masterlet[pos[a]] == letter[a]){ timesran[a] = timesran[a] +1; if (timesran[a] == timestorun[a]){ console.log("ELSE THING"+pos[a]+rando+timestorun[a]); shouldiFlip[a] = 0; } } } The output of the first console log here is
hi there you are in new run now03undefined jquery.solari.letters.js:386 As you can see, timesran[] is coming back undefined. This makes me sad.
Am I handling this correctly? I've been working on this for about 7 hours perfecting the code and this is my last hangup. Thank you for your help!!!