Get value of selected radio button
<p>I am attempting to make a small Javascript quiz, and the way I'm trying to get it to work is to check and see if the value in the radio button element matches the one in an object property (labeled correctAnswer).</p>

<pre><code>var allQuestions = [{
question: ["Question1?", "Question2?", "Question3"], 
choices: [["choice1-1", "choice1-2", "choice1-3", "choice1-4"], ["choice2-1", "choice2-2", "choice2-3", "choice2-4"], ["choice3-1", "choice3-2", "choice3-3", "choice3-4"]], 
correctAnswer: ["choice 1-4", "choice2-3", "choice3-2"]}];  

var questions = document.getElementById('question');
var button = document.getElementById('next');
var radio = document.getElementsByName('buttons');
var a = document.getElementById('a');
var b = document.getElementById('b');
var c = document.getElementById('c');
var d = document.getElementById('d');
var labels = document.getElementsByName('labels');


for(var j=0; j &lt; radio.length; j++) {
radio[j].value = allQuestions[0].choices[0][j];
}

for (var k=0; k &lt; radio.length; k++) {
labels[k].innerHTML = allQuestions[0].choices[0][k];
}

var score = 0;


questions.innerHTML = allQuestions[0].question[0];
var i = 0;
var correct = allQuestions[0].correctAnswer[i];
button.onclick = function() {

if (i &lt; allQuestions[0].question.length) {
i++;
if(radio.sel)
for(var l=0; l &lt; radio.length; l++) {  
    questions.innerHTML = allQuestions[0].question[i]; //sets the question at top of page
    radio[l].value = allQuestions[0].choices[i][l]; //sets value of each radio button.
    //labels[l].innerHTML = allQuestions[0].choices[i][l]; //sets options for each question
    a.innerHTML = allQuestions[0].choices[i][0];
    b.innerHTML = allQuestions[0].choices[i][1];
    c.innerHTML = allQuestions[0].choices[i][2];
    d.innerHTML = allQuestions[0].choices[i][3];
    } 

}
</code></pre>

<p>I am thinking that to match the value of the selected radio button with whatever the correct answer of the question is, it should read something similar to this:</p>

<pre><code>if(radio.checked.value == allQuestions[0].correctAnswer[i]) {
score++;
}
</code></pre>

<p>But that specifically isn't working when I put it at the top of the function.  Any advice?</p>
