Solved

Creating a exam page II

Posted on 2003-11-27
13
222 Views
Last Modified: 2010-04-09
I would like to have it check against answers on the QFinal.html or what ever it would take to
do it. Sorry this is a after thought.

Example:

RESULTS

1. A         Correct ( Have this text in green)
2. B         Wrong ( Have this in red ) A is the correct answer



At the bottom of the QFinal page have a box like a " Next " box for each question, where I could click to go to that question or would it be best to just add a link. So, it would then go to Q2 and I could review, then I guess I could click the back button in the browser and it would take me back to the QFinal page. What would it take to get it to score a %.
0
Comment
Question by:CMILLER
  • 7
  • 6
13 Comments
 
LVL 15

Expert Comment

by:Timbo87
ID: 9835368
Hi Chris,

Here is the new modified QFinal.html. For now the answers are in the document. Tell me if this is what you want and I'll try to hide the answers for the final product.

<html>
<head>
<title>Results</title>
</head>
<body>
<center>
<h2>Results</h2>
</center>
<br>
<script language="JavaScript" type="text/javascript">
var anCheck = new Array();
anCheck[0] = "A"
anCheck[1] = "B"
anCheck[2] = "C"
anCheck[3] = "D"
anCheck[4] = "C"
anCheck[5] = "B"
anCheck[6] = "A"
anCheck[7] = "B"
anCheck[8] = "C"
anCheck[9] = "D"
anCheck[10] = "ACD"
wn = window.location+""
var answers = new Array()
var astring = wn.substring(wn.indexOf("html") + 5,wn.length)
var ancnt = 0
var corcnt = 0

for(i=0;i<astring.length;i++)
{
if(astring.charAt(i) == ",")
{
ancnt++
continue;
}
if(answers[ancnt] == null) answers[ancnt] = ""
answers[ancnt] += astring.charAt(i)
}
document.write("<table border=0>")
for(j=0;j<answers.length;j++)
{
if(answers[j] == anCheck[j])
{
followup = "<font color=green>Correct</font>"
corcnt++
}
else
followup = "<font color=red>Wrong " + anCheck[j] + " is the correct answer.</font> <a href='Q" + eval(j+1) + ".html'>View Question</a>"
document.write("<tr><td>" + eval(j+1) + ".</td>" + "<td>" + answers[j] + "</td>" + "<td>" + followup + "</td></tr>")
}
document.write("</table><br><br><center>" + corcnt + " out of " + answers.length + " correct. <br><h3>" + Math.round((corcnt/answers.length*100)) + "%</h3>")

</script>
<input type="button" value="Print Results" onClick="window.print()">
</center>
</body>
</html>

You can view it online at: http://timbo87.home.comcast.net/temp/quiz/Q1.html
0
 

Author Comment

by:CMILLER
ID: 9838599
Yes, That looks good!!
0
 
LVL 15

Expert Comment

by:Timbo87
ID: 9838802
How "encrypted" do you want the answers to be? I could just change them so 0 is A, 1 is B, 2 is C, 3 is D. Or I could mix them up so A is $, B is @, C is #, and D is !. It really depends on how concerned you are about the users trying to cheat and grab the answers out of the code.
0
Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

 

Author Comment

by:CMILLER
ID: 9838919
I would say use the $, @, # !, good idea
0
 
LVL 15

Expert Comment

by:Timbo87
ID: 9839048
I had to make one change. ~ is A. So the pattern is:

~ = A
@ = B
# = C
! = D

Here is the final code:

<html>
<head>
<title>Results</title>
</head>
<body>
<center>
<h2>Results</h2>
</center>
<br>
<script language="JavaScript" type="text/javascript">
var anCheck = new Array();
anCheck[0] = "~"
anCheck[1] = "@"
anCheck[2] = "#"
anCheck[3] = "!"
anCheck[4] = "#"
anCheck[5] = "@"
anCheck[6] = "~"
anCheck[7] = "@"
anCheck[8] = "#"
anCheck[9] = "!"
anCheck[10] = "~#!"
wn = window.location+""
var answers = new Array()
var astring = wn.substring(wn.indexOf("html") + 5,wn.length)
var ancnt = 0
var corcnt = 0

for(i=0;i<astring.length;i++)
{
if(astring.charAt(i) == ",")
{
ancnt++
continue;
}
if(answers[ancnt] == null) answers[ancnt] = ""
answers[ancnt] += astring.charAt(i)
}
document.write("<table border=0>")
var t
var s
for(t=0;t<anCheck.length;t++)
{
rD = /~/gi;rC = /@/gi;rB = /#/gi;rA = /!/gi;
anCheck[t] = anCheck[t].replace(rD,"A");anCheck[t] = anCheck[t].replace(rC,"B");
anCheck[t] = anCheck[t].replace(rB,"C");anCheck[t] = anCheck[t].replace(rA,"D");
}
for(j=0;j<answers.length;j++)
{
if(answers[j] == anCheck[j])
{
followup = "<font color=green>Correct</font>"
corcnt++
}
else
followup = "<font color=red>Wrong " + anCheck[j] + " is the correct answer.</font> <a href='Q" + eval(j+1) + ".html'>View Question</a>"
document.write("<tr><td>" + eval(j+1) + ".</td>" + "<td>" + answers[j] + "</td>" + "<td>" + followup + "</td></tr>")
}
document.write("</table><br><br><center>" + corcnt + " out of " + answers.length + " correct. <br><h3>" + Math.round((corcnt/answers.length*100)) + "%</h3>")

</script>
<input type="button" value="Print Results" onClick="window.print()">
</center>
</body>
</html>

You can view it online at: http://timbo87.home.comcast.net/temp/quiz/Q1.html
0
 
LVL 15

Accepted Solution

by:
Timbo87 earned 500 total points
ID: 9839057
Made one small change:

QFinal.html

<html>
<head>
<title>Results</title>
</head>
<body>
<center>
<h2>Results</h2>
Do NOT click "Next" when reviewing questions. Click Back instead to return to this page.
</center>
<br>
<script language="JavaScript" type="text/javascript">
var anCheck = new Array();
anCheck[0] = "~"
anCheck[1] = "@"
anCheck[2] = "#"
anCheck[3] = "!"
anCheck[4] = "#"
anCheck[5] = "@"
anCheck[6] = "~"
anCheck[7] = "@"
anCheck[8] = "#"
anCheck[9] = "!"
anCheck[10] = "~#!"
wn = window.location+""
var answers = new Array()
var astring = wn.substring(wn.indexOf("html") + 5,wn.length)
var ancnt = 0
var corcnt = 0

for(i=0;i<astring.length;i++)
{
if(astring.charAt(i) == ",")
{
ancnt++
continue;
}
if(answers[ancnt] == null) answers[ancnt] = ""
answers[ancnt] += astring.charAt(i)
}
document.write("<table border=0>")
var t
var s
for(t=0;t<anCheck.length;t++)
{
rD = /~/gi;rC = /@/gi;rB = /#/gi;rA = /!/gi;
anCheck[t] = anCheck[t].replace(rD,"A");anCheck[t] = anCheck[t].replace(rC,"B");
anCheck[t] = anCheck[t].replace(rB,"C");anCheck[t] = anCheck[t].replace(rA,"D");
}
for(j=0;j<answers.length;j++)
{
if(answers[j] == anCheck[j])
{
followup = "<font color=green>Correct</font>"
corcnt++
}
else
followup = "<font color=red>Wrong " + anCheck[j] + " is the correct answer.</font> <a href='Q" + eval(j+1) + ".html'>View Question</a>"
document.write("<tr><td>" + eval(j+1) + ".</td>" + "<td>" + answers[j] + "</td>" + "<td>" + followup + "</td></tr>")
}
document.write("</table><br><br><center>" + corcnt + " out of " + answers.length + " correct. <br><h3>" + Math.round((corcnt/answers.length*100)) + "%</h3>")

</script>
<input type="button" value="Print Results" onClick="window.print()">
</center>
</body>
</html>
0
 
LVL 15

Expert Comment

by:Timbo87
ID: 9839233
Found a little leftover unused code. You can delete these two lines:

var t
var s
0
 

Author Comment

by:CMILLER
ID: 9839288
Great Job, It All Works
0
 

Author Comment

by:CMILLER
ID: 9839427
Well I spoke to soon, I found a problem.

anCheck[1] = "~"
anCheck[2] = "@"
anCheck[3] = "#"
anCheck[4] = "!"
anCheck[5] = "#"
anCheck[6] = "@"
anCheck[7] = "~"
anCheck[8] = "@"
anCheck[9] = "#"
anCheck[10] = "!"
anCheck[11] = "~@"

I changed it from starting with anCheck[0] = "~",
to anCheck[1] = "~", because It is tied to the Q#,
But after I changed to [1], it will not work. I can leave it as [0]
but it throws all the Q#'s off by "1".
0
 
LVL 15

Expert Comment

by:Timbo87
ID: 9839434
Sorry, I'll fix it shortly.
0
 

Author Comment

by:CMILLER
ID: 9839435
Well, wait a min, let me change some things, I think I am wrong
0
 
LVL 15

Expert Comment

by:Timbo87
ID: 9839439
Ah, I see what you're talking about. The array is actually 1 behind the questions. Q1.html refers to anCheck[0]. It's the nature of arrays to start at 0.
0
 

Author Comment

by:CMILLER
ID: 9839446
I fixed it, I changed it back to start with [0], and reformated all the questions to point to the next one.
0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
SASS allows you to treat your CSS code in a more OOP way. Let's have a look on how you can structure your code in order for it to be easily maintained and reused.
In this tutorial viewers will learn how to position items using CSS's three positioning types Create a new HTML document with an internal stylesheet.: Create another div in CSS and name it Absolute : Type "position:absolute;" and "top:10px; left:50p…
In this tutorial viewers will learn how to style a corner ribbon overlay for an image using CSS Create a new class by typing ".Ribbon":  Define the class' "display:" as "inline-block": Define its "position:" as "relative": Define its "overflow:" as …

813 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now