title: Variable content is not saved in the function
body: <p>I have a problem that I can't find a solution for.
  In my code there is a variable called <code>list</code>.
  The variable <code>list</code> is supposed to retrieve input elements using <code>getElementsByName()</code>, 
  but this variable is empty (i.e. <code>list.length == 0</code>) after the <code>if</code> statement
  has ended.
  In the code below, at the beginning of the <code>for</code> loop the <code>list.length</code> is zero or undefined.</p>
  
  <p>Why does this happen?</p>
  
  <p>The function is:</p>
  
  <pre><code>function chekRadioToAnswer() {
      var signAnswers = new Array(0, 0, 0, 0);
      var grades = [[0, 5, 10, 15], [15, 12, 10, 5, 0], [0, 5, 10, 15, 20], [0, 0, 20, 30]];
      var answers = new Array(0, 0, 0, 0, 0, 0);
  
      for (num = 2; num &lt;= 5; num++) {
          if (num == 2) {
              list = document.getElementsByName("answer2"); 
          }
          if (num == 3) {
              list = document.getElementsByName("answer3"); 
          }
          if (num == 4) {
              list = document.getElementsByName("answer4"); 
          }
          if (num == 5) {
              list = document.getElementsByName("answer5"); 
          }
  
          for (i = 0; i &lt; list.length; i++) {
              if (list[i].checked) {
                  var value = document.getElementById("hiddenAnswers").getAttribute("value");
                   document.getElementById("hiddenAnswers").setAttribute("value", (value + grades[num - 2][i]));
                   break;
               }
          }
  
          list.length = 0;
      }
      return false;
  } 
  </code></pre>