Javascript: passing a variable into a function results in undefined
<p>this is my first javascript project and I'm having trouble passing a variable into a function.</p>

<p>Here is the relevant section from my "global variables"</p>

<pre><code>var timesran = [];
for (var x= 0; x&lt;38; x++){
timesran[x] = 0;
}
</code></pre>

<p>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</p>

<pre><code>function happytimes(){
for (var x= 0; x &lt; 38; x++){
    switch (x){
        case 0:
            if (shouldiFlip[x]){
                randomizer(x);  //input that we want to feed into the function
                x++;
            }
}
</code></pre>

<p>(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)</p>

<p>Following is the randomizer function</p>

<pre><code>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] &gt;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;
            }
    }   
}
</code></pre>

<p>The output of the first console log here is </p>

<pre><code>hi there you are in new run now03undefined jquery.solari.letters.js:386
</code></pre>

<p>As you can see, timesran[] is coming back undefined. This makes me sad.</p>

<p>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!!!</p>
