title: How to add values of radio buttons in JavaScript?
body: <p>I'm very much an amateur programmer, and I was wondering if there is a way to neatly and simply add up the values of radio buttons? I thought that my code was pretty self-explanitory,  but I keep receiving a return value of zero.</p>
  
  <pre><code>&lt;script&gt;
  
  var x1;
  x1 = 0
  var x2;
  x2 = 0
  var x3;
  x3 = 0
  var x4;
  x4 = 0
  var x5;
  x5 = 0
  var x6;
  x6 = 0
  
  
  //q1
  
  if(document.getElementById("q1a").checked) 
  {
  x1 = 3
  }
  elseif(document.getElementById("q1b").checked)
  {
  x1 = 1
  }
  elseif(document.getElementById("q1c").checked)
  {
  x1 = 5
  }
  
  //q2
  
  if(document.getElementById("q2a").checked)
  {
  x2 = 4
  }
  elseif(document.getElementById("q2b").checked)
  {
  x2 = 2
  }
  
  //q3
  
  if(document.getElementById("q3a").checked)
  {
  x3 = 1
  }
  elseif(document.getElementById("q3b").checked)
  {
  x3 = 5
  }
  elseif(document.getElementById("q3c").checked)
  {
  x3 = 3
  }
  
  //q4
  
  if(document.getElementById("q4a").checked)
  {
  x4 = 4
  }
  elseif(document.getElementById("q4b").checked)
  {
  x4 = 2
  }
  
  //q5
  
  if(document.getElementById("q5a").checked)
  {
  x5 = 3
  }
  elseif(document.getElementById("q5b").checked)
  {
  x5 = 5
  }
  elseif(document.getElementById("q5c").checked)
  {
  x5 = 1
  }
  
  //q6
  
  if(document.getElementById("q6a").checked)
  {
  x6 = 2
  }
  elseif(document.getElementById("q6b").checked)
  {
  x6 = 4
  }
  
  function test()
  {
  var score
  score = (x1 + x2 + x3 + x4 + x5 +x6)
  document.writeln("score is " + score);
  }
  
  &lt;/script&gt;
  &lt;body&gt;
  &lt;br&gt;
          &lt;br&gt;
          &lt;input type="radio" name="q1" id="q1a" value ="3"&gt; &lt;br&gt;
          &lt;input type="radio" name="q1" id="q1b" value ="1"&gt; &lt;br&gt;
          &lt;input type="radio" name="q1" id="q1c" value ="5"&gt; &lt;br&gt;
          &lt;br&gt;
  
          &lt;br&gt;
          &lt;input type="radio" name="q2" id="q2a" value="4"&gt; &lt;br&gt;
          &lt;input type="radio" name="q2" id="q2b" value="2"&gt; &lt;br&gt;
          &lt;br&gt;
  
          &lt;br&gt;
              &lt;input type="radio" name="q3" id="q3a" value="1"&gt; &lt;br&gt;
              &lt;input type="radio" name="q3" id="q3b" value="5"&gt; &lt;br&gt;
              &lt;input type="radio" name="q3" id="q3c" value="3"&gt; &lt;br&gt;
          &lt;br&gt;
  
          &lt;br&gt;
           &lt;input type="radio" name="q4" id="q4a" value="4"&gt; &lt;br&gt;
           &lt;input type="radio" name="q4" id="q4b" value="2"&gt; &lt;br&gt;
          &lt;br&gt;
  
          &lt;br&gt;
          &lt;input type="radio" name="q5" id="q5a" value="3"&gt; &lt;br&gt;
          &lt;input type="radio" name="q5" id="q5b" value="5"&gt; &lt;br&gt;
          &lt;input type="radio" name="q5" id="q5c" value="1"&gt; &lt;br&gt;
          &lt;br&gt;
  
          &lt;br&gt;
          &lt;input type="radio" name="q6" id="q6a" value="2"&gt; &lt;br&gt;
          &lt;input type="radio" name="q6" id="q6b" value="4"&gt; &lt;br&gt;
  
  &lt;button onclick="test()"&gt; Test &lt;/button&gt;
  </code></pre>