Quiz

The example shows how to create a Quiz

                        

    
        Survey.StylesManager.applyTheme("default");
    


var json = {
  title: "American History",
  showProgressBar: "bottom",
  showTimerPanel: "top",
  maxTimeToFinishPage: 10,
  maxTimeToFinish: 25,
  firstPageIsStarted: true,
  startSurveyText: "Start Quiz",
  pages: [
    { questions: [ {type: "html", html: "You are about to start quiz by history. <br/>You have 10 seconds for every page and 25 seconds for the whole survey of 3 questions.<br/>Please click on <b>'Start Quiz'</b> button when you are ready." } ] },
    {
      questions: [
        {
          type: "radiogroup",
          name: "civilwar",
          title: "When was the Civil War?",
          choices: [ "1750-1800", "1800-1850", "1850-1900", "1900-1950", "after 1950" ],
          correctAnswer: "1850-1900"
        }
      ]
    },
    {
      questions: [
        {
          type: "radiogroup",
          name: "libertyordeath",
          title: "Who said 'Give me liberty or give me death?'",
          choicesOrder: "random",
          choices: [ "John Hancock", "James Madison", "Patrick Henry", "Samuel Adams" ],
          correctAnswer: "Patrick Henry"
        }
      ]
    },
    {
      maxTimeToFinish: 15,
      questions: [
        {
          type: "radiogroup",
          name: "magnacarta",
          title: "What is the Magna Carta?",
          choicesOrder: "random",
          choices: [ "The foundation of the British parliamentary system", "The Great Seal of the monarchs of England", "The French Declaration of the Rights of Man", "The charter signed by the Pilgrims on the Mayflower" ],
          correctAnswer: "The foundation of the British parliamentary system"
        }
      ]
    }
  ],
  completedHtml: "<h4>You have answered correctly <b>{correctedAnswers}</b> questions from <b>{questionCount}</b>.</h4>"
};

window.survey = new Survey.Model(json);


survey.onComplete.add(function(result) {
    document.querySelector('#surveyResult').innerHTML = "result: " + JSON.stringify(result.data);
});


$("#surveyElement").Survey({ 
    model: survey 
});


                    
<!DOCTYPE html>
<html>
<head>
    <title>The example shows how to create a Quiz, jQuery Survey Library Example</title>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <script src="https://unpkg.com/jquery"></script>
<script src="https://surveyjs.azureedge.net/1.0.55/survey.jquery.js"></script>
<link href="https://surveyjs.azureedge.net/1.0.55/survey.css" type="text/css" rel="stylesheet" />
    <link rel="stylesheet" href="./index.css">

</head>
<body>
                <div id="surveyElement">
            </div>
    <div id="surveyResult"></div>

<script type="text/javascript" src="./index.js"></script>

</body>
</html>

You may use the first page as the start page.

survey.firstPageIsStarted = true;

You may hide the previous button from the navigation.

survey.showPrevButton = false;

You may set the maximum time to complete the survey (in seconds)

survey.maxTimeToFinish = 30;
and/or pages in seconds
survey.maxTimeToFinishPage = 10;
You may override the default time for a specific page
survey.pages[0].maxTimeToFinish = 20;

You may always start or stop timer.

survey.startTimer();
survey.stopTimer();

Show timer panel on top or bottom. If showTimerPanel value is different from "none", the startTimer() function is called on render.

survey.showTimerPanel = "top";

Use showTimerPanelMode property or/and onTimerPanelInfoText event to control the timer panel text.

survey.showTimerPanelMode = "page";

Use question.correctAnswer to the set correct answer to questions. After that you may use {correctedAnswers} and {inCorrectedAnswers} variables, for example in completedHtml.