Can someone explain what this snippet of code is doing?
<p>Im trying to learn javascript by tracing through some code at the moment, I was wondering if someone could explain what is happening in this snippet of code (this snippet is just part of a function hence no closing brace):</p>

<pre><code>document.addEventListener("keydown",function(e){

        for(i=0;i &lt; keys.length; i++) {

            if(e.keyCode == keys[i]){

            var tri = document.getElementById("foo").childNodes[i];

            if(i==0){
                var tri = document.getElementById("foo").childNodes[1];
            }

            if(i==1){
                var tri = document.getElementById("foo").childNodes[3];
            }

            if(i &gt; 1) {
                var tri = document.getElementById("foo").childNodes[(i*2)+1];
            }
</code></pre>

<p>The part im confused about most in this is the childNodes[] and the if(i) statements?</p>
