ennui
09-27-2003, 11:44 PM
First off, let me start by saying that I know very little about JavaScript.
I am having problems with a quiz that I found at http://www.bridgewater.edu/cescc/acadcomp/JSQuizMaker/
The thing is once you take the quiz, it brings up a pop up that gives you the score. I was wondering if there is a way to make it have 2 different pop ups, depending on the score...one for a 100% score and one if the score is not 100%.
here is the part of the script that deals with the new window.. if you can please help I would be verry thankful.. you can contact me either here or at my e-mail. ennuinet@hotmail.com
<script language="JavaScript">
function make_2d_array(n, m) {
var a = new Array(n);
for (var j=1; j<=n; j++) {
a[j] = new Array(m);
}
return a
}
function getSelection(elem,len) {
// finds which true or false or which multiple choice option was selected
var limit = elem + len;
for (var i=elem; i<limit; i++) {
if (document.forms[0].elements[i].checked) {
return i-elem+1
}
}
return 0
}
function gradeReport (form,nTF,aTF,nmulti,amulti) {
var init, limit, select, ans, temp;
var ncorrect = 0;
var question = 0;
if (document.forms[0].elements[1].value == "") {
alert("IMPORTANT! Your name was left blank. For recording purposes, "
+ "please identify yourself with your first and last names.")
document.forms[0].elements[1].value =
prompt("Please enter your first and last names here.","");
return
}
if (document.forms[0].elements[2].value == "") {
alert("IMPORTANT! Your email address was left blank. To "
+ "facilitate communication, an email address is essential. ")
document.forms[0].elements[2].value =
prompt("Please enter your email address here.","");
return
}
var newWin =
window.open("","quizWin",
"scrollbars,resizable,height=200,width=440,toolbar,status,menubar")
newWin.document.close();
newWin.document.open();
if (newWin != null) {
var msg = "<HTML><HEAD><TITLE>Quiz Results</TITLE></HEAD>"
msg += "<BODY bgcolor=#d0ffff>"
msg += "<center><H1>Quiz Results</H1></center><p>"
msg += "Your correct answers are in <b>black</b> and your incorrect "
msg += "answers are in <b><font color=red>red_X</font></b> with the "
msg += "'_X' added. Print a copy of these results for your records. "
msg += "<b><i>Close this browser to complete this activity!</i><p>"
msg += "Name = "
msg += document.forms[0].elements[1].value+"<p>";
msg += "Email Address = "
msg += document.forms[0].elements[2].value+"<p>";
if (nTF > 0) {
init = 3; // equals the number of non-question data fields
// at the beginning of the quiz form
limit = init + 2 * nTF;
for (var i=init; i<limit; i=i+2) {
question = question+1;
select = getSelection(i,2);
if (select == 0) {
msg += question+". "+qTF[question]+" = ";
ans = "";
}
else {
msg += question+". "+qTF[question]+" = "
ans = document.forms[0].elements[select+i-1].value;
}
if (ans != aTF[question]) {
temp = ans + "_X";
msg += "<font color=red>"
msg += temp+"</font><p>"
}
else {
ncorrect = ncorrect + 1;
msg += ans+"<p>"
}
}
}
if (nmulti > 0) {
init = 3 + 2 * nTF;
limit = init + nchoices * nmulti;
question = question - nTF;
for (var i=init; i<limit; i=i+nchoices) {
question = question+1;
select = getSelection(i,nchoices);
if (select == 0) {
msg += (question+nTF)+". "+qmulti[question]+" = ";
ans = "";
}
else {
msg += (question+nTF)+". "+qmulti[question]+" = "
ans = document.forms[0].elements[select+i-1].value;
}
if (select != amulti[question]) {
temp = ans + "_X";
msg += "<font color=red>"
msg += temp+"</font><p>"
}
else {
ncorrect = ncorrect + 1;
msg += ans+"<p>"
}
}
}
ans = "TOTAL CORRECT = "+ncorrect+" out of "+(nTF + nmulti)
document.forms[0].elements[0].value = ans;
msg += " "+ans+"<p></b></BODY></HTML>"
newWin.document.write(msg)
newWin.document.close()
form.submit();
newWin.focus();
}
return
}
<!-- -->
</script>
I am having problems with a quiz that I found at http://www.bridgewater.edu/cescc/acadcomp/JSQuizMaker/
The thing is once you take the quiz, it brings up a pop up that gives you the score. I was wondering if there is a way to make it have 2 different pop ups, depending on the score...one for a 100% score and one if the score is not 100%.
here is the part of the script that deals with the new window.. if you can please help I would be verry thankful.. you can contact me either here or at my e-mail. ennuinet@hotmail.com
<script language="JavaScript">
function make_2d_array(n, m) {
var a = new Array(n);
for (var j=1; j<=n; j++) {
a[j] = new Array(m);
}
return a
}
function getSelection(elem,len) {
// finds which true or false or which multiple choice option was selected
var limit = elem + len;
for (var i=elem; i<limit; i++) {
if (document.forms[0].elements[i].checked) {
return i-elem+1
}
}
return 0
}
function gradeReport (form,nTF,aTF,nmulti,amulti) {
var init, limit, select, ans, temp;
var ncorrect = 0;
var question = 0;
if (document.forms[0].elements[1].value == "") {
alert("IMPORTANT! Your name was left blank. For recording purposes, "
+ "please identify yourself with your first and last names.")
document.forms[0].elements[1].value =
prompt("Please enter your first and last names here.","");
return
}
if (document.forms[0].elements[2].value == "") {
alert("IMPORTANT! Your email address was left blank. To "
+ "facilitate communication, an email address is essential. ")
document.forms[0].elements[2].value =
prompt("Please enter your email address here.","");
return
}
var newWin =
window.open("","quizWin",
"scrollbars,resizable,height=200,width=440,toolbar,status,menubar")
newWin.document.close();
newWin.document.open();
if (newWin != null) {
var msg = "<HTML><HEAD><TITLE>Quiz Results</TITLE></HEAD>"
msg += "<BODY bgcolor=#d0ffff>"
msg += "<center><H1>Quiz Results</H1></center><p>"
msg += "Your correct answers are in <b>black</b> and your incorrect "
msg += "answers are in <b><font color=red>red_X</font></b> with the "
msg += "'_X' added. Print a copy of these results for your records. "
msg += "<b><i>Close this browser to complete this activity!</i><p>"
msg += "Name = "
msg += document.forms[0].elements[1].value+"<p>";
msg += "Email Address = "
msg += document.forms[0].elements[2].value+"<p>";
if (nTF > 0) {
init = 3; // equals the number of non-question data fields
// at the beginning of the quiz form
limit = init + 2 * nTF;
for (var i=init; i<limit; i=i+2) {
question = question+1;
select = getSelection(i,2);
if (select == 0) {
msg += question+". "+qTF[question]+" = ";
ans = "";
}
else {
msg += question+". "+qTF[question]+" = "
ans = document.forms[0].elements[select+i-1].value;
}
if (ans != aTF[question]) {
temp = ans + "_X";
msg += "<font color=red>"
msg += temp+"</font><p>"
}
else {
ncorrect = ncorrect + 1;
msg += ans+"<p>"
}
}
}
if (nmulti > 0) {
init = 3 + 2 * nTF;
limit = init + nchoices * nmulti;
question = question - nTF;
for (var i=init; i<limit; i=i+nchoices) {
question = question+1;
select = getSelection(i,nchoices);
if (select == 0) {
msg += (question+nTF)+". "+qmulti[question]+" = ";
ans = "";
}
else {
msg += (question+nTF)+". "+qmulti[question]+" = "
ans = document.forms[0].elements[select+i-1].value;
}
if (select != amulti[question]) {
temp = ans + "_X";
msg += "<font color=red>"
msg += temp+"</font><p>"
}
else {
ncorrect = ncorrect + 1;
msg += ans+"<p>"
}
}
}
ans = "TOTAL CORRECT = "+ncorrect+" out of "+(nTF + nmulti)
document.forms[0].elements[0].value = ans;
msg += " "+ans+"<p></b></BODY></HTML>"
newWin.document.write(msg)
newWin.document.close()
form.submit();
newWin.focus();
}
return
}
<!-- -->
</script>