Skip to main content

test by gkwithmath

TEST 1



Question x of y

function Quiz(questions) { this.score = 0; this.questions = questions; this.questionIndex = 0; } Quiz.prototype.getQuestionIndex = function() { return this.questions[this.questionIndex]; } Quiz.prototype.guess = function(answer) { if(this.getQuestionIndex().isCorrectAnswer(answer)) { this.score++; } this.questionIndex++; } Quiz.prototype.isEnded = function() { return this.questionIndex === this.questions.length; } function Question(text, choices, answer) { this.text = text; this.choices = choices; this.answer = answer; } Question.prototype.isCorrectAnswer = function(choice) { return this.answer === choice; } function populate() { if(quiz.isEnded()) { showScores(); } else { // show question var element = document.getElementById("question"); element.innerHTML = quiz.getQuestionIndex().text; // show options var choices = quiz.getQuestionIndex().choices; for(var i = 0; i < choices.length; i++) { var element = document.getElementById("choice" + i); element.innerHTML = choices[i]; guess("bt" + i, choices[i]); } showProgress(); } }; function guess(id, guess) { var button = document.getElementById(id); button.onclick = function() { quiz.guess(guess); populate(); } }; function showProgress() { var currentQuestionNumber = quiz.questionIndex + 1; var element = document.getElementById("progress"); element.innerHTML = "Question " + currentQuestionNumber + " of " + quiz.questions.length; }; function showScores() { var gameOverHTML = "

Result

"; gameOverHTML += "

Your scores: " + quiz.score + "

"; var element = document.getElementById("quiz"); element.innerHTML = gameOverHTML; }; // create questions var questions = [ new Question("What is the Capital of India?", ["New Delhi", "Mumbai","Jaipur", "Kolkata"], "New Delhi"), new Question("National Animal of India?", ["Elephant", "Bengal Tiger","Lion", "Cow"], "Bengal Tiger"), new Question("National River of India?", ["Yamuna", "Ganga","Brahmputra", "Sindhu"], "Ganga"), new Question("तू कौन है ?", ["पागल ", "गधा","मेंचल", "दिमाग"], "दिमाग"), ]; var quiz = new Quiz(questions); populate();

Comments

Popular posts from this blog

Scientific name of FRUIT,TREE, VEG.

        FRUIT NAME                                                             SCIENTIFIC NAME   APPLE                                                                    1. PYRIS MALUS            BANANA                                                                2. MUSA PARADISICUM BANYAN TREE                                           ...

ENGLISH Vocabulary

                                           English vocabulary : 1  1 . MORDANT:   having or showing a sharp or critical quality; biting. 2. APPOSITE: Appropreate  3. Liaison:   communication or cooperation which facilitates a close working relationship between people or organizations.