Dynamic quiz
improving skills in javaascript!!!!
HTML
<body>
<header>
<hgroup>
<h1>This is my Dynamic Quiz</h1>
<h2>Using html5 / css / javascript</h2>
</hgroup>
</header>
<section id='description'>
<p>This quiz is compossed by 10 questions, you have to answer at least 7 from 10 to pass the exam.</p>
<h2>Lets start!</h2>
</section>
<div id='questions-number'>
<p>Question <span id='current-question'>1</span> of <span>10</span> </p>
</div>
<section id='questions'>
<p id='question'></p>
<form id='myForm'>
<input type='radio' name='quiz' id='0' value='0'/><label id='answer0'>answer0</label></li></br>
<input type='radio' name='quiz' id='1' value='1'/><label id='answer1'>answer1</label></br>
<input type='radio' name='quiz' id='2' value='2'/><label id='answer2'>answer2</label></br>
<input type='radio' name='quiz' id='3' value='3'/><label id='answer3'>answer3</label></br>
</form>
</section>
<div id='score'></div>
<div id='back'>
back
</div>
<div id='next'>
next
</div>
</body>
CSS
*
{
color: #F2F2F2;
font-family: helvetica,arial;
font-size: 1em;
text-align: center;
}
body
{
background: #287D7D;
}
form
{
text-align:left;
margin: 0 auto;
display: inline-block;
width: 15%;
}
h1, h2
{
color: #F2F2F2;
font-size: 2em;
margin:0 0 1% 0;
text-align: left;
text-shadow: 2px 2px 1px rgba(12,40,60,1);
}
h2
{
font-size: 1.3em;
margin:0;
}
header
{
background: #1C344C;
box-shadow: 0 4px 5px rgba(18,42,66, .6);
display: inline-block;
padding: 2% 5%;
width: 89%;
margin-bottom: 2%
}
input
{
padding:0;
margin:0 0 1em 0;
display: inline-block;
}
label
{
margin:0 0 0 1em;
display: inline-block;
vertical-align: top;
}
p
{
margin:0;
padding: 0;
}
span
{
margin: 0;
background: #1C344C;
padding: .5% 1.5%;
font-size: 3em;
}
#answer0,#answer1,#answer2,#answer3,#question
{
transition: all .3s ease;
}
#description
{
display: inline-block;
background: #C6E070;
padding: 1% 0;
margin-bottom: 3%;
width: 99%;
}
#description h2
{
display: inline-block;
text-align: center;
}
#next, #back
{
cursor:pointer;
background: #A1283C;
display: inline-block;
margin: 0 auto;
padding: 1% 2%;
text-shadow: 1px 1px 1px rgba(0,0,0, .5);
font-size: 1.4em;
box-shadow: 1px 1px 1px #63172C;
transition: all .2s ease;
}
#next:hover
{
font-size: 1.2em;
box-shadow: -1.5px -1.5px 1px #F7305B;
}
#question
{
margin-bottom: 1.5em;
}
#questions-number
{
display: inline-block;
background: #F2F2F2;
padding: 1% 0;
margin-bottom: 3%;
width: 99%
}
#questions-number p
{
color: #1C344C;
}
#score
{
padding: 1% 2%;
margin: 0 auto 1em auto;
width: 25%;
background: #A1283C;
display:none;
}
JavaScript
$(document).on('ready', ready);
function ready(){
var allQuestions =
[
{
question: "Whats my real name?",
choices: ["Jhonnatan", "Alberto", "Tatan","Jaime"],
answer: 0
},
{
question: "Who is Colombia's president?",
choices: ["Alvaro Uribe", "Andres Pastrana", "Juan Manuel Santos","Tatan"],
answer: 2
},
{
question: "My favorite super heroe?",
choices: ["Batman", "Flash", "Tatan","Javascript"],
answer: 3
},
{
question: "Wich sports do i practice?",
choices: ["Climbing", "Swimming", "Programming","Running"],
answer: 0
},
{
question: "Whats my dad's name?",
choices: ["Alberto", "Jorge", "Javier","Jose"],
answer: 1
},
{
question: "Whats my favorite color?",
choices: ["Red", "Purple", "Blue","All"],
answer: 2
},
{
question: "My favorite alcoholic drink",
choices: ["Vodka", "Aguardiente", "Rum","Tekila"],
answer: 3
},
{
question: "Whats my favorite kind of music?",
choices: ["Hardcore", "Reggaeton", "Salsa","Programming"],
answer: 0
},
{
question: "How many qestions has this quiz??",
choices: ["20", "8", "10","12"],
answer: 2
},
{
question: "My favorite programming lenguage?",
choices: ["Ruby", "Arduino", "Python","Javascript"],
answer: 3
}
];
var score = 0;
var number=0;
var state=0;
var question = $('#question');
var choice1 = $('#answer0');
var choice2 = $('#answer1');
var choice3 = $('#answer2');
var choice4 = $('#answer3');
var next = $('#next');
var back = $('#back');
var questions = $('#questions');
var currentQuestion = $('#current-question');
var answers = new Array (allQuestions.length);
addQuestionAndAnswers();
next.on('click', changeQuestion);
back.on('click', backQuestion);
function addQuestionAndAnswers() {
currentQuestion.text(number +...