JSFiddle - React, Tailwind, and code Playground
HTML
<div>
<h1>Sneakerhead Quiz</h1>
<h2>Question <span id="currentQ"></span> / <span id="totalQ"></span></h2>
<h3 id="q_holder"></h3>
<img class="intro" src="http://i.imgur.com/TlbWQj5.jpg" />
<img id="q_img" src="" />
<fieldset class="choiceList"></fieldset>
<button id="start">Start Quiz</button>
<button class="next" disabled>Next Question</button>
<button class="last" disabled>Last Question</button>
<button class="score" disabled>See your score</button>
</div>
CSS
body {
font-family: 'arial';
}
h2, .next, .last, .score {
display: none;
}
img {
height: 150px;
float: left;
border-radius: 10px;
}
fieldset {
border: none;
height: 155px;
}
.error {
color: #f30000;
}
button {
width: 150px;
height: 50px;
border: solid 1px #ccc;
border-radius: 4px;
background: #666;
color: #efefef;
font-size: 1.1em;
font-weight: bold;
}
button:hover {
background: #777
}
button:disabled {
background: #555;
color: #777;
}
JavaScript
var questions = [{
text : 'This is the first signature shoe of what famous basketball player?',
imgUrl : 'http://i.imgur.com/sZcZ316.jpg',
options : ['Clyde Drexler','Michael Jordan','Larry Bird','Magic Johnson'],
correctAnswer : 1
},{
text : 'Who is this famous basketball fan and sneaker collaborator?',
imgUrl : 'http://i.imgur.com/qnSO5Fe.jpg',
options : ['Steve Urkel','Derek Jeter','Tyler Perry','Spike Lee'],
correctAnswer : 3
},{
text : 'Who is the greatest basketball player of all-time?',
imgUrl : 'http://i.imgur.com/WUrp5OD.png',
options : ['LeBron James','Kobe Bryant','Michael Jordan','"Pistol" Pete Maravich'],
correctAnswer : 2
}],
currentAnswer = 0,
userScore = 0;
document.getElementById('totalQ').innerHTML = questions.length;
document.getElementById('start').addEventListener('click', startQuiz, false);
function startQuiz(){
$('#start').remove();
$('.intro').remove();
$('.next').fadeIn();
$('h2').fadeIn();
showQuestions(questions, 0);
showChoices(questions, 0);
$('#q_img').fadeIn();
$('#q_holder').fadeIn();
}
function nextQuestion() {
var firstAnswer = questions[0].correctAnswer;
if (currentAnswer === firstAnswer) {
userScore++;
}
$('.next').remove();
$('.last').fadeIn('slow');
showQuestions(questions, 1);
showChoices(questions, 1);
$('#q_img').fadeIn();
$('#q_holder').fadeIn();
}
function lastQuestion() {
var secondAnswer = questions[1].correctAnswer;
if (currentAnswer === secondAnswer) {
userScore++;
}
showQuestions(questions, 2);
showChoices(questions, 2);
$('.last').remove();
$('.score').fadeIn('slow');
$('#q_img').fadeIn();
$('#q_holder').fadeIn();
}
function showScore() {
var lastAnswer = questions[2].correctAnswer;
if (currentAnswer === lastAnswer) {
userScore++;
}
$('h2').remove();
$('#q_holder').remove();
...