<div id="css-script-menu">
<div class="css-script-clear"></div>
</div>
<h1 style="margin-top: 175px; color:#fff" align="Center">Quiz</h1>
<div class="card0">
<h2 style="margin-top: 20px; margin-bottom: 40px; color:##f08b3b" align="center">Look at my?</h2>
<p><input type="radio" id="cat" name="card1" value="Cat, my cat is fluffy." /> Cat, my cat is fluffy.</p>
<p><input type="radio" id="rabbit" name="card1" value="Rabbit, my rabbit is cute." /> Rabbit, my rabbit is cute.</p>
<p><input type="radio" id="horse" name="card1" value="Horse, my horse is amazing." /> Horse, my horse is amazing.</p>
<p><input type="radio" id="monkey" name="card1" value="Monkey, my monkey is cool." /> Monkey, my monkey is cool.</p>
</div>
<div class="card1">
<h2 style="margin-top: 20px; margin-bottom: 40px; color:##f08b3b" align="center">How does one cut down the mightiest tree in the forrest?</h2>
<p><input type="radio" id="saw" name="card2" value="With a saw." /> With a saw.</p>
<p><input type="radio" id="apple" name="card2" value="With an apple." /> With an apple.</p>
<p><input type="radio" id="tea spoon" name="card2" value="With a tea spoon." /> With a tea spoon.</p>
<p><input type="radio" id="herring" name="card2" value="With a herring." /> With a herring.</p>
</div>
<div class="card2">
<h2 style="margin-top: 20px; margin-bottom: 40px; color:##f08b3b" align="center">"I did not hit her! I did naaaaaht.."?</h2>
<p><input type="radio" id="ok" name="card2" value="Ok." /> Ok.</p>
<p><input type="radio" id="Good for you" name="card2" value="Good for you." /> Good for you.</p>
<p><input type="radio" id="Oh, hi Mark!" name="card2" value="Oh, hi Mark!" /> Oh, hi Mark!</p>
<p><input type="radio" id="monkey" name="You're my favorite customer." value="You're my favorite customer." /> You're my favorite customer.</p>
</div>
<div class="card3">
<h2 style="margin-top: 20px; margin-bottom: 40px; color:##f08b3b" align="center">You've finished the quiz! You scored <div...
// initialize values on window object to make universally available
window.val = "";
window.userScore = 0;
window.questionIndex = 0;
var allQuestions = [{
question0: "Look at my?",
choices: ["Rabbit, my rabbit is cute.", "Cat, my cat is fluffy.", "Horse, my horse is amazing.", "Monkey, my monkey is cool."],
correctAnswer: 2
}, {
question1: "How does one cut down the mightiest tree in the forrest?",
choices: ["With a saw.", "With an apple.", "With a tea spoon.", "With a herring."],
correctAnswer: 3
}, {
question2: "I did not hit her! I did naaaaaht..?",
choices: ["Ok.", "Good for you.", "Oh, hi Mark!", "You're my favorite customer."],
correctAnswer: 2
}
];
var main = function () {
$('.card1').hide();
$('.card2').hide();
$('.card3').hide();
};
$('input:radio').click(function () {
window.val = $('input:radio:checked').val()
});
$('.next').click(function () {
if (!$('input:radio:checked').val()) {
alert("You did not provide input!")
} else {
$('input:radio').prop("checked", false); // uncheck radiobuttons for next radio selection
var answerIndex = allQuestions[window.questionIndex].correctAnswer;
var thisAnswer = allQuestions[window.questionIndex].choices[answerIndex];
if (window.val == thisAnswer) {
window.userScore++;
} else {
// do nothing
}
var compiler = '$(\'.card' + window.questionIndex + '\')';
var currentCard = eval(compiler);
var nextCard = currentCard.next();
if (window.questionIndex < 2) {
currentCard.hide();
nextCard.show();
} else if (window.questionIndex == 2 ) {
currentCard.hide();
nextCard.show();
$('.next').hide();
window.questionIndex ++;
var finalScore = window.questionIndex + " out of 3 questions!";
$('div#userscoreHTML').html(finalScore);
} else {
// do nothing
}
...
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.