Solved

Creating a exam page II

Posted on 2003-11-27
13
225 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
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Building a website can seem like a daunting task to the uninitiated but it really only requires knowledge of two basic languages: HTML and CSS.
This article discusses how to create an extensible mechanism for linked drop downs.
In this tutorial viewers will learn how to embed Flash content in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <object> tag to embed Flash content.: To specify that the object is Flash content, d…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

856 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