JSFiddle - React, Tailwind, and code Playground

by Emanuel Vecchio

HTML

<form id="quiz"></form>

JavaScript

var allQuestions = [
      {question: "1. Grand Central Terminal, Park Avenue, New York is the world's: ", 
      options: ["largest railway station", "highest railway station","longest railway station", "none of the above"], 
      correctAnswer: 0
    },
      {question: "2. Entomology is the science that studies: ", 
      options: ["Behavior of human beings", "Insects", "The origin and history of technical and scientific terms", "The formation of rocks"],
      correctAnswer: 1
    },
      {question:"3. Eritrea, which became the 182nd member of the UN in 1993, is in the continent of: ",
      options: ["Asia", "Africa", "Europe", "Australia"], 
      correctAnswer: 1
    },
      {question: "4. Garampani sanctuary is located at: ", 
      options: ["Junagarh, Gujarat", "Diphu, Assam","Kohima, Nagaland", "Gangtok, Sikkim"], 
      correctAnswer: 1
    }, 
      {question: "5. For which of the following disciplines is Nobel Prize awarded?", 
      options: ["Physics and Chemistry",
          "Physiology or Medicine", "Literature, Peace and Economics", "All of the above"], 
      correctAnswer: 3
    }];

var quiz = document.getElementById("quiz");
var currentQuestion = 0;
var answers = 0;

function displayQuestion (num) {
    quiz.innerHTML = "";
    
    var questionObj = allQuestions[num];
    var questions = questionObj["question"];
    var questionDiv = document.createElement("div");
    var questionText = document.createTextNode(questions);
    var options = questionObj["options"];
    var optionsDiv = document.createElement("div");

    
    questionDiv.appendChild(questionText);
    
    for (var i = 0; i < options.length; i++) {
        var radio = document.createElement("input");
        radio.type = "radio";
        radio.id = i;
        radio.value = i;
        radio.name = "option";
        radio.required = true;
        
        optionsDiv.appendChild(radio);
        
        var label = document.createElement("label");
        label.for =...