JS Quiz
Simple JS, multiple choice quiz, based off of github.com/jrue/JavaScript-Quiz with some modifications to the functionality and bootstrap implementation
by WhitneyBlank
HTML
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/twitter-bootstrap/2.2.1/css/bootstrap-combined.min.css">
<script src="https://code.jquery.com/jquery-1.11.1.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
<div class="form-group rsform-block rsform-block-framecontent">
<div id="frame" role="content"></div>
</div>
<hr>
<div class="form-group rsform-block rsform-block-placecontent">
<label class="col-sm-3 control-label formControlLabel" data-toggle="tooltip" title="" for="placecontent"></label>
<div class="col-sm-6 formControls">
<textarea cols="50" rows="5" name="form[placecontent]" id="placecontent" readonly="" class="rsform-text-box form-control rsform-text-box"></textarea>
</div>
</div>
<div class="col-sm-6 formControls rsform-block-submit">
<button type="submit" name="form[submit]" id="submit" onclick="copyText()" class="rsform-submit-button btn btn-primary">Submit Quiz</button>
</div>
CSS
input { height:30px !important; }
input[type=checkbox] { height:30px !important; margin-top:-3px !important; margin-right:5px !important; box-shadow:none; background-color:#ffffff; position:relative !important; }
textarea { width: 90%; margin: 0 auto; display: block; }
input[type=radio] { height:30px !important; margin-top:-3px !important; margin-right:5px !important; box-shadow:none; background-color:#ffffff; position:relative !important; }
.form-group input, .form-group select { height:30px; padding: 0px 12px; }
.form-horizontal .form-group { margin:10px; }
.formContainer .formControlLabel { width:auto !important; min-width:150px; margin:0; padding:0; }
.formControls { width:100%; padding:0; margin: 10px 0 20px auto; }
.radio { padding-top:0 !important; padding-left:8px !important; }
.radio-inline { margin-right:10px; padding-top:0 !important; display:inline; }
.bold { font-weight:bold; }
.italic { font-style:italic; }
.clear { width:100%; margin:0 !important; }
.rsform-block-submit { display:none; }
.show { display: block !important; }
/* .rsform-block-placecontent { display:none; } */
#submit { margin:0 auto; display:block; }
/* QUIZ STYLES */
ol,ul { list-style:none; }
strong { font-weight:700; }
#frame { width:auto; max-width: 800px; background:transparent; margin:3px auto; padding:10px; color:#333 !important; }
div#frame h2 { width:auto; border-bottom:1px solid #bdbdbd; padding:0 0 5px 0; font-size:30px; }
h3.question { font-weight:normal; margin:20px 0; padding:0; font-style:italic; display:block; }
p.pager { margin:5px 0 5px; color:#999; text-align:right; }
.qnumber { font-size:25px; font-weight:bold; font-style:italic; vertical-align:bottom; }
.number...
JavaScript
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script src="https://code.jquery.com/jquery-1.11.1.min.js" integrity="sha256-VAvG3sHdS5LqTT+5A/aeq/bZGa/Uj04xKxY8KM/w9EE=" crossorigin="anonymous"></script><script src="https://stackpath.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script><script>
var quiztitle = "Humanitarian news quiz";
/**
* Set the information about your questions here. The correct answer string needs to match
* the correct choice exactly, as it does string matching. (case sensitive)
*
*/
/**
*Let's create the randomization of the questions!
*/
function shuffle(array) {
var currentIndex = array.length, temporaryValue, randomIndex;
// While there remain elements to shuffle...
while (0 !== currentIndex) {
// Pick a remaining element...
randomIndex = Math.floor(Math.random() * currentIndex);
currentIndex -= 1;
// And swap it with the current element.
temporaryValue = array[currentIndex];
array[currentIndex] = array[randomIndex];
array[randomIndex] = temporaryValue;
}
return array;
}
if (!("scramble" in Array.prototype)) {
Object.defineProperty(Array.prototype, "scramble", {
enumerable: false,
value: function() {
var o, i, ln = this.length;
while (ln--) {
i = Math.random() * (ln + 1) | 0;
o = this[ln];
this[ln] = this[i];
this[i] = o;
}
return this;
}
});
}
var quiz = [
{
"question" : "Q1: How many locations in Syria does the UN classify as besieged?",
"image" : "",
"choices" : [
"Zero",
"One",
"Four",
"Nine"
],
"correct" : "Zero",
"explanation" : "The UN used to classify...