Your host: Stephen Chapman
Analysis Quiz
This quiz has no right and wrong answers. Instead each answer has a numeric value assigned to it and the values for the selected answers are added up to give a final total which is then converted into a percentage figure where zero percent means that the lowest valued answer was selected every time and 100 percent means that the highest valued answer was selected each time. If intermediate valued answers are selected or a mix of high and low valued answers is selected then an intermediate percentage value will result.
Step One - Fill out the following form for each question that you want to contain within your quiz. Each time you press the "Add Question" button the code in the textarea immediately below will be updated to add the new question and answers to those you have already added to the quiz. Once you have all your questions entered highlight the content of the text area and copy/paste it into a new JavaScript file (eg. quizhead.js).
Step Two - add the following code immediately before the </head> tag in the page where you want the quiz displayed.
<script src="quizhead.js" type="text/javascript"></script>
Step Three - select the JavaScript in the following textarea and save it as quizbody.js.
quizbody.js
// Analysis Quiz Javascript
// copyright 20th December 2004 - 13th May 2005, by Stephen Chapman
// permission to use this Javascript on your web page is granted
// provided that all of the code in this script (including these
// comments) is used without any alteration
function displayResult(cor) {
document.write('<div style="font-size:14px;"><b>You have completed the quiz.<\/b><\/div><blockquote><span style="font-size:12px;"> <br \/> <br \/> <br \/> <br \/><\/span><\/blockquote><div><a href="'+analPage+'?cor='+cor+'">Your result</a><\/div>');
}
var qsParm = new Array();
function qs() {
var query = window.location.search.substring(1);
var parms = query.split('&');
for (var i=0; i<parms.length; i++) {
var pos = parms[i].indexOf('=');
if (pos > 0) {
var key = parms[i].substring(0,pos);
var val = parms[i].substring(pos+1);
qsParm[key] = val;
}
}
}
qsParm['questnum'] = 0;
qsParm['cor'] = 0;
qs();
var questnum = qsParm['questnum'];
var cor = qsParm['cor'];cor=cor%475;
function checkAnswer(e,b,g){
var a = -1; var x = Math.floor(g/b); // x = bdca
for (var i=0; i<e.c.length; i++) {if (e.c[i].checked) {a = i;}}
if (a == -1) {
alert("You must select an answer");
return false;
}
var b = new Array();
b[1] = Math.floor(x/1000); x -= b[1]*1000;
b[3] = Math.floor(x/100); x -= b[3]*100;
b[2] = Math.floor(x/10); b[0] = x - b[2]*10;
cor += b[a];
var www = self.location.href.lastIndexOf('?');
var thispage = self.location.href;
if (www != -1) thispage = self.location.href.substr(0,www);
questnum++;
var p = Math.floor((Math.random() * 8) + 2);
var m = (p * 475) +cor;
top.location = thispage + '?questnum='+ questnum +'&cor='+m;
return false;
}
function result(cor) {
var lo = 0, hi = 0;
for (var i=0;i < quiz.length;i++) {
var f = quiz[i].split('~');
lo += parseInt(f[7]); hi += parseInt(f[8]);
}
return Math.round((cor - lo) * 100 / (hi - lo));
}
var tblsz = quiz.length;
document.write('<table align="center" cellpadding="3" width="350" border="1"><tr>');
if (questnum < quiz.length) {
var f = quiz[questnum].split('~');
document.write('<td align="left"><form name="myForm"><div style="font-size:14px;">Question: '+f[2]+'</div><blockquote><span style="font-size:12px;">\n');
document.write('<input type="radio" name="c" value="0" /> '+f[3]+'<br />\n');
document.write('<input type="radio" name="c" value="1" /> '+f[4]+'<br />\n');
if (f[5] != '') document.write('<input type="radio" name="c" value="2" /> '+f[5]+'<br />\n');
if (f[6] != '') document.write('<input type="radio" name="c" value="3" /> '+f[6]+'<\/span><\/blockquote>\n');
document.write('<div align="right"><input type="button" value="Next Question" onclick="checkAnswer(myForm,'+f[1]+','+f[0]+');return false;" /><\/div><\/form>\n');
} else {
document.write('<td align="center">\n');
document.write('<form name="myForm">');
displayResult(result(cor));
document.write('<\/form>\n');}
document.write('<\/td><\/tr><\/table>\n');
Step Four - attach this script into the body of your question page where you want the quiz question to appear using:
<script src="quizbody.js" type="text/javascript"></script>
Step Five - Set up the Analysis Quiz Answers page.
Related Articles
Copyright © Felgall Pty Ltd