Solved

Creating a exam page II

Posted on 2003-11-27
13
220 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
Comment Utility
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
Comment Utility
Yes, That looks good!!
0
 
LVL 15

Expert Comment

by:Timbo87
Comment Utility
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
 

Author Comment

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

Expert Comment

by:Timbo87
Comment Utility
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
Comment Utility
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
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 
LVL 15

Expert Comment

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

var t
var s
0
 

Author Comment

by:CMILLER
Comment Utility
Great Job, It All Works
0
 

Author Comment

by:CMILLER
Comment Utility
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
Comment Utility
Sorry, I'll fix it shortly.
0
 

Author Comment

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

Expert Comment

by:Timbo87
Comment Utility
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
Comment Utility
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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

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 four methods for overlaying images in a container on a web page
In this tutorial viewers will learn how add a full-size background image to a webpage using CSS3. Create a new HTML document with an internal stylesheet.: In CSS, define the html element to have a background image. Use a high resolution image.: In t…
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 …

728 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

10 Experts available now in Live!

Get 1:1 Help Now