Note that there are some explanatory texts on larger screens.

plurals
  1. POUsing Javascript object in HTML
    primarykey
    data
    text
    <p>I have made a simple quiz in Javascript and want to display it in an HTML page. I cut and pasted the Javascript object with the questions and answers into the head of the HTML.</p> <p>My question is how can I display each question with it's choices and then when I click the "Next" button the next question will come up?</p> <p>I also have some logic to add in which calculates score on the quiz but that is for another question.</p> <pre><code>&lt;!DOCTYPE html&gt; &lt;html lang="en"&gt; &lt;head&gt; &lt;title&gt;The quiz&lt;/title&gt; &lt;script&gt; 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} ]; &lt;/script&gt; &lt;/head&gt; &lt;body&gt; &lt;section&gt; &lt;h1&gt;Welcome to the quiz!&lt;h1&gt; &lt;form name="quiz"&gt; &lt;label for="choice"&gt;QUESTION HERE&lt;/label&gt; &lt;br&gt;&lt;input type="radio" name="choice" value="1"&gt;CHOICE HERE&lt;/input&gt; &lt;br&gt;&lt;input type="radio" name="choice" value="2"&gt;CHOICE HERE&lt;/input&gt; &lt;br&gt;&lt;input type="radio" name="choice" value="3"&gt;CHOICE HERE&lt;/input&gt; &lt;br&gt;&lt;input type="submit" value="Next"&gt; &lt;/form&gt; &lt;/section&gt; &lt;/body&gt; &lt;/html&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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