Question

In: Computer Science

QUESTION 2 You are developing an online quiz web application and you have been asked to...

QUESTION 2 You are developing an online quiz web application and you have been asked to design a JSON file for creating a TestBank. You need to design the JSON file for storing some multiple choice questions/answers. Here is an example of sample data which you need to convert it into JSON Q) 5 + 7 * 2 = ? a) 14 b) 12 c) 24 d) 19 ANS: d Answer the following questions: 1) How do you design the JSON file? Create the JSON file (for 5 sample test-questions) and validate it. 2) Develop a jQuery program which displays all questions, their multiple options, and the right answer.

Solutions

Expert Solution

var allQuestions = null;
var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function() {
    if (this.readyState == 4 && this.status == 200) {
        allQuestions = JSON.parse(this.responseText);
        console.log(allQuestions);

        var currentPage = -1;
        var totalScore = 0;
        var review = false;

        $(document).ready(function () {
            $("#quiz").hide();
            $("#alert").hide();
            $("#nextButton").html("Start Quiz");


            $("#nextButton").click(function(){
                $("#nextButton").html("Next");

                var answerArray = $("#myForm").serializeArray();

                // check if question has been answered
                if(answerArray.length==0 && currentPage>=0 && review==true) {
                    $("#alert").html("Please select an answer.");
                    $("#alert").fadeIn('fast');
                } else {
                    $("#alert").hide();

                    if(review) {
                        // evaluate question answered and add to score
                        $("input[type=radio]").attr('disabled', true);
                        $(".a"+allQuestions[currentPage].correctAnswer).addClass("correctAnswer");
                        if(answerArray[0].value == allQuestions[currentPage].correctAnswer) {
                            totalScore++;
                        } else {
                         $(".a"+answerArray[0].value).addClass("wrongAnswer");
                        }

                        review = false; // review completed
                    } else {
                        $("#content").fadeOut('slow',function(){
                            currentPage++; // iterate to next question
                            if(currentPage==allQuestions.length){ // Show Score
                                // quiz is over
                                $("p").show();
                                $("#quiz").hide();
                                $("#nextButton").hide();
                                $("p").html("You answered <span class='score'>"+totalScore+"/"+allQuestions.length+"</span> questions correctly!");
                            } else {
                                review = true; // turn review on for next question
                                var thisQ = allQuestions[currentPage];
                                // display a question
                                $("p").hide();
                                $("#quiz").show();
                                $("#form-question").html(thisQ.question);
                                $("#form-answers").empty();
                                var choiceArray = thisQ.choices;
                                for(var i=0; i<choiceArray.length; i++) {
                                    $("#form-answers").append('<div class="form-radio a'+i+'"><input type="radio" name="q'+currentPage+'" value="'+i+'"> ' + choiceArray[i] + '</div>');
                                }
                            }
                        });
                        $("#content").fadeIn('slow');
                    }

                }
            })
        });
        
    } /* else {
        $("p").show();
        $("#quiz").hide();
        $("#nextButton").hide();
        $("#alert").hide();
        $("p").html("Error accessing file.");
    } */
};
xmlhttp.open("GET", "quiz-data.json", true);
xmlhttp.send();

Quizdata.json

[
{
"question": "Which is NOT a real element?",
"choices": ["Hydrogen", "Radium", "Vibranium", "Arsenic"],
"correctAnswer": 2
},
{
"question": "Which is NOT a layer of the atmosphere?",
"choices": ["Taposphere", "Thermosphere", "Exosphere", "Stratosphere"],
"correctAnswer": 0
},
{
"question": "Which is the most abundant gas in the atmosphere?",
"choices": ["Hydrogen", "Oxygen", "Nitrogen", "Helium"],
"correctAnswer": 2
},
{
"question": "Which element is all life on Earth based on?",
"choices": ["Hydrogen", "Oxygen", "Silicon", "Carbon"],
"correctAnswer": 3
},
{
"question": "Water evaporates, condenses in the atmosphwere, and falls back to the earth as rain. What is this process called?",
"choices": ["Wheel of time", "Water cycle", "Water exogenesis", "Fun times"],
"correctAnswer": 1
}
]

Related Solutions

Question 2 You have been asked to devise a psychological achievement test (PAT) that will be...
Question 2 You have been asked to devise a psychological achievement test (PAT) that will be administered to students who select Nursing as their major course. Describe the steps you will take to ensure that psychological achievement test is a good intelligence test
You have been asked to design a web page for a local business or organization (choose...
You have been asked to design a web page for a local business or organization (choose one from your local community). Go to www.flickr.com or www.1StopPictures.com and choose a visual to illustrate the website by trying to match the personality of the organization to a visual image. Then, identify the primary categories of information that need to be included on the page. Develop a flow chart or map that shows how a typical user would navigate through the site. What...
Question 2 (Marks: 35) You have been asked to assist in the bookkeeping for Camden Stores....
Question 2 (Marks: 35) You have been asked to assist in the bookkeeping for Camden Stores.  The business is a registered VAT vendor and trades only with registered VAT vendors.  The business charges 15% VAT on all its sales. All amounts are inclusive of VAT, unless otherwise stated or not applicable.  The business uses the perpetual inventory system and uses different mark‐ups for the different products they sell and all discount is incidental in nature.  Cash...
QUESTION 2: ETHICS, INDEPENDENCE & GOVERNANCE You have been asked by Tian, a friend of yours,...
QUESTION 2: ETHICS, INDEPENDENCE & GOVERNANCE You have been asked by Tian, a friend of yours, to help clarify a few matters relating to his new job. He has recently joined Zipit Ltd, a company listed on the New Zealand Stock Exchange, as an assistant accountant. He explains that GKPM, the company’s auditors arrived the previous week. As this is his first experience of being audited, there are a few things he does not understand. Knowing that you are studying...
You have been asked to explain how the time value of money affects the application of...
You have been asked to explain how the time value of money affects the application of the Federal unified transfer taxes for a presentation at your school's homecoming seminar. To help you prepare for the presentation, select either "Yes" or "No" to indicate how the time value of money affects the application of the Federal unified transfer taxes. a. The Federal unified transfer tax system is unified and cumulative in effect. b. Gift tax liability incurred represents a postpayment of...
The project description: As a programmer, you have been asked to write a Java application, using...
The project description: As a programmer, you have been asked to write a Java application, using OOP concepts, for a Hospital with the following requirements: • The Hospital has several employees and each one of them has an ID (int), name (string), address (string), mobile phone number (string), email (string) and salary (double) with suitable data types. • The employees are divided into: o Administration staff: who have in addition to the previous information their position (string). o Doctor: who...
As a programmer, you have been asked to write a Java application, using OOP concepts, for...
As a programmer, you have been asked to write a Java application, using OOP concepts, for a Hospital with the following requirements: • The Hospital has several employees and each one of them has an ID (int), name (string), address (string), mobile phone number (string), email (string) and salary (double) with suitable data types. • The employees are divided into: o Administration staff: who have in addition to the previous information their position (string). o Doctor: who have also a...
Question 2 ch 9 You have been asked to prepare a December cash budget for Ashton...
Question 2 ch 9 You have been asked to prepare a December cash budget for Ashton Company, a distributor of exercise equipment. The following information is available about the company’s operations: The cash balance on December 1 is $50,600. Actual sales for October and November and expected sales for December are as follows: October November December Cash sales $ 74,400 $ 86,000 $ 85,000 Sales on account 515,000 533,000 672,000 Sales on account are collected over a three-month period as...
The Python Question is as follows: You have been asked by a manager of a store...
The Python Question is as follows: You have been asked by a manager of a store to identify the items most commonly bought together (the manager would like to place these items in close proximity). You are given a file, receipts.txt , that contains the receipts of the last 1000 transactions in the following format, where each line of the file is a single receipt: eggs, bread, milk, lettuce cheese, milk, apples bread, milk bread, cheese, milk Write a function...
An online poll at a popular web site asked the following: A nationwide ban of the...
An online poll at a popular web site asked the following: A nationwide ban of the diet supplement ephedra went into effect recently. The herbal stimulant has been linked to 155 deaths and many more heart attacks and strokes. Ephedra manufacturer NVE Pharmaceuticals, claiming that the FDA lacked proof that ephedra is dangerous if used as directed, was denied a temporary restraining order on the ban yesterday by a federal judge. Do you think that ephedra should continue to be...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT