$(document).ready(function() {
var allQuestions = [
{question:"What is the currency of Madagascar?", choices:["rupi", "ariary", "franc"], correctAnswer:1},
{question : "Who was the second man on the moon?", choices:["Neil","Buzz", "Michael"], correctAnswer:1},
{question : "Where is the White Sea?", choices:["Europe", "Asia", "America"],correctAnswer:0}
];
var x= 0;
var counter = 0;
//remove the introduction and presents the first question
$('.rdy').on('click', function(){
$(".quiz").removeClass('hidden');
$(".message2").remove();
$(this).remove();
$(".sendAnswer").removeClass("invis");
$(".ques").text(allQuestions[x].question);
$("#c0").text(allQuestions[x].choices[0]);
$("#c1").text(allQuestions[x].choices[1]);
$("#c2").text(allQuestions[x].choices[2]);
});
//this checks the correctness when answer is entered, and responds
$("#foo").on('click',function() {
$(this).addClass("invis");
$(".next").toggleClass("invis");
y = x+1;
$(".quiz").addClass('hidden');
if ($('input[name="response"]:checked').val() == allQuestions[x].correctAnswer)
$(".feedback").text("Good job, that's correct!") ;
else
$(".feedback").text("Sorry, that is the wrong answer.");
//this keeps score
if ($('input[name="response"]:checked').val() == allQuestions[x].correctAnswer)
//the if clauses are duplicated, but it doesnt work when combined
{$("#score").text(counter+1);
counter++;}
else
$("#score").text(counter);
$(".tally").toggleClass("hidden");
$("#numOfQuestions").text(allQuestions.length);
if (y == allQuestions.length)
...
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Fiddle Pages
Your fiddles accessible under a custom domain and a vanity path - the simplest hosting for your personal project.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Get Fiddle Pages with PRO
Your fiddles accessible under a custom domain and a vanity path - the simplest hosting for your personal project.