I'm creating a quiz and I have radio buttons that need to be used to select answers.
I'm using an array which contains objects that have 3 properties.
a property asks the question.
a property holds an array of answers.
a property that has the index value of the correct answer from the array of answers.
Basically it looks like this:
var questions = [{question1: "What color is the sky?", answers:["blue", "red", "green", "orange"], correctAnswer: 0}];
correctAnswer: 0 is the index value of blue.
I'm at the point where I need to start putting the values of these objects into the markup.
For example, I have 4 radio buttons in my html.
<form id="buttons">
<input type="radio" name="answer" value="0"><br>
<input type="radio" name="answer" value="1"><br>
<input type="radio" name="answer" value="2"><br>
<input type="radio" name="answer" value="3"><br>
</form>
I need javascript to input the answers to my question next to my radio buttons and I want to test if the person selected the correct answer by checking if the value of the radio button is the same as the index value inside the object.
so it would look like this with the above array example.
<form id="buttons">
<input type="radio" name="answer" value="0">blue<br>
<input type="radio" name="answer" value="1">red<br>
<input type="radio" name="answer" value="2">green<br>
<input type="radio" name="answer" value="3">orange<br>
</form>
the correct answer in the example would be the value = "0";
I hope this is not too confusing. I am working on the week 4 quiz project from http://javascriptissexy.com/how-to-learn-javascript-properly/