Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Ok since you're new to JavaScript, here's a little complete code I'm writing. First you don't need any form when all your data is static. So just replace your entire Form block with following </p> <pre><code>&lt;label for="choice" id="question"&gt;QUESTION HERE&lt;/label&gt; &lt;br&gt;&lt;input type="radio" id='choice1' name="choice" value="1"&gt;CHOICE HERE&lt;/input&gt; &lt;br&gt;&lt;input type="radio" id="choice2" name="choice" value="2"&gt;CHOICE HERE&lt;/input&gt; &lt;br&gt;&lt;input type="radio" id="choice3" name="choice" value="3"&gt;CHOICE HERE&lt;/input&gt; &lt;br&gt;&lt;button id="next"&gt;Next&lt;/button&gt; </code></pre> <p>Now just include a separate JavaScript file or write following code below the HTML declaration in script tag.</p> <pre><code>var questions = [{question: "Whos the best bball player?", choices: ["Lebron James", "Kobe Bryant", "Kevin Durant", "Javale McGee"], correctAnswer:0}, {question: "Name the Miami Heat player?", choices: ["Camelo Anthony", "Kevin Love", "Paul Pierce", "Dwayne Wade"], correctAnswer:3}, {question: "Name the LA Lakers player?", choices: ["Lebron James", "Kobe Bryant", "Kevin Durant", "Javale McGee"], correctAnswer:1}, {question: "What team does Melo play for?", choices: ["Chicago Bulls", "Utah Jazz", "New York Knicks", "Orlando Magic"], correctAnswer:2}]; var index = 0; var totalLength = questions.length; $("#next").on("click", function() { if(index &lt; totalLength) { var questionObject = questions[index]; $("#question").text(questionObject.question); $("#choice1").text(questionObject.choices[0]); $("#choice2").text(questionObject.choices[1]); $("#choice3").text(questionObject.choices[2]); index++; } }); </code></pre> <p>As you can see whenever you can click the button, the next question if available in array, will be shown in the page.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload