Code:
<html>
<head>
<title>State Capitols Quiz</title>
<style type="text/css">
.chkans {
margin:10px 10px -5px 0;
}
span.chkans {
position:relative;
top:5px
}
* html span.chkans {
top:2px
}
</style>
</head>
<body>
<h1>State Capitols Quiz</h1>
This page will tell what you know about state capitols.<br>
<h2>Directions:</h2>
Click on the correct answer.<br><br>
<script type="text/javascript">
/*/////////////////////////////
* Quiz Writing & Scoring Script
* © 2005 John Davenport Scheuer
* jscheuer1TAKEOUTCAPSFOREMAIL@comcast.net
* permission to use granted
* this credit must stay intact
/////////////////////////////*/
//Set to 0 for no answers given away
//Set to 1 to allow peeking
var allowPeeking=1
//Set to 0 for no Starting Over without refresh
//Set to 1 to allow Easy Do Overs
var allowDoOvers=1
questions=new Array();
//Set Questions and Answers Arrays Below.
//Questions come first. Then come the answer pairs:
//Follow the right answer with "right", all wrong ones with ""
questions[0]=["What is the capitol of Pennsylvania?", "Harrisburg", "right", "Oswego", "", "Philadelphia", "", "Denver", ""]
questions[1]=["What is the capitol of New Jersey?", "Princeton", "", "North Orange", "", "Trenton", "right", "Labrador", ""]
questions[2]=["What is the capitol of Montana?", "Billings", "", "Helena", "right", "Shelby", "", "Tabasco", ""]
questions[3]=["What is the capitol of New York?", "Syracuse", "", "New York City", "", "Buffalo", "", "Albany", "right"]
questions[4]=["What is the capitol of Kansas?", "Atchison", "", "Topeka", "right", "Dodge City", "", "Manhattan", ""]
questions[5]=["Are we having fun yet?", "Yes", "right", "No", ""]
////////////////Stop Editing///////////////
for (i = 0; i < questions.length; i++){
for (j = 0; j < questions[i].length; j++){
if (questions[i][j]=="")
questions[i][j]=("w"+i)+j
if (questions[i][j]=="right")
questions[i][j]="right"+i
}
}
var ie=document.all
function showAnswer(el,ans){
ie? ie[el].innerHTML='The answer is: '+ ans : document.getElementById(el).innerHTML='The answer is: '+ ans
}
function addup() {
var q, right, statement, total=0
quizQuests=new Array();
for (i = 0; i < questions.length; i++)
quizQuests[i]=0
if (document.forms.quiz.q0['right0']){
for (i = 0; i < questions.length; i++){
q="q"+i
right="right"+i
if (document.forms.quiz[q][right].checked)
quizQuests[i]=1
}
}
else if (document.getElementById){
for (i = 0; i < questions.length; i++){
right="right"+i
if (document.getElementById(right).checked)
quizQuests[i]=1
}
}
else
return;
for (i = 0; i < questions.length; i++)
total += quizQuests[i]
/*/////////////////////////////////////////////////
Set score response below.
///////////////////Edit Below to Suit/////////////*/
statement='You scored '+ total +' out of '+ questions.length +' correct, '+ Math.round(total/questions.length*100) +'%'
/////////////////Stop Editing///////////////////
ie? ie.results.innerHTML=statement : document.getElementById('results').innerHTML=statement
}
function clearR(){
ie? ie.results.innerHTML='' : document.getElementById('results').innerHTML=''
for (i = 0; i < questions.length; i++)
if (allowPeeking)
ie? ie["ans"+i].innerHTML='' : document.getElementById("ans"+i).innerHTML=''
window.scrollTo(0,0);
}
document.write('<hr><form name="quiz">')
var correct, answersString
for (i = 0; i < questions.length; i++){
answersString=''
for (k = 1; k < questions[i].length; k+=2)
answersString+='<input id="'+questions[i][(k+1)]+'" type="radio" unchecked name="q'+i+'"><label for="'+questions[i][(k+1)]+'">'+questions[i][k]+'</label><br>'
for (j = 0; j < questions[i].length; j++){
if (questions[i][j]=="right"+i)
correct=questions[i][j-1]
}
with (document){
write('Question '+(i+1)+':<br>')
write(questions[i][0]+'<br>')
write(answersString)
if (allowPeeking)
write('<input class="chkans" type="button" value="Check Answer" onclick="showAnswer(\'ans'+i+'\',\''+correct+'\')"> <span id="ans'+i+'" class="chkans"></span><br> ')
write('<br>')
}
}
with (document){
write('<hr><br>')
write('<input type="button" value="See Score" onclick="addup()"> <span id="results"></span><br> <br>')
if (allowDoOvers)
write('<input type="button" value="Start Again" onclick="reset();clearR()">')
write('</form>')
}
</script>
</body></html>
Bookmarks