bradz1993
03-13-2012, 05:46 PM
function displayMessage(text) {
// Open a new window
var msgWindow = window.open('', 'Message');
// Write message in the new Window
msgWindow.document.write(text);
// Raise this window, in case it's not visible
msgWindow.focus();
}
//Enter total number of questions:
var totalquestions=31
var mcquestions=13
var saquestions=18
var correctchoices=new Array("a","a","b","c","b","c","a","a","b","c","a","b","b");
var correctanswers=new Array("memory locations","_ underscore","x=5+5;","20","Else","lose win","ticker = ticker + 1;","Ticker = ticker + 1;","300.000","Jonathon \b","var","var counter;","var mark = 50, 70");
var shortanswers=new Array("identifier","assignment","false","true","false","reverse of the boolean result","the variable will be once the line is executed","var","value","2","4","2","3","no semi colon","no space/between else and if","missing curly bracket/no curly bracket","need else instead of else if");
function gradeit(){
var actualchoices=new Array()
var msg1=new Array()
var correctanswersno=0
var t=0
var sa=0
var displaycorrectanswers=""
for (q=1;q<=mcquestions;q++){
var thequestion=eval("document.Questionform.q"+q)
for (c=0;c<thequestion.length;c++){
if (thequestion[c].checked==true)
actualchoices[q]=thequestion[c].value
}
if (actualchoices[q]==correctchoices[q]){
msg1[t]=q+")"+" Correct";
correctanswersno = correctanswersno + 1;
t = t + 1;
} else {
msg1[t]=q+")"+" Incorrect: <br>Correct Answer: "+correctchoices[q]+") "+correctanswers[q];
t = t + 1;
}
}
for (s=1;s<=saquestions;s++){
var saanswers=("document.Questionform.sa"+s).match(shortanswers[s-1]);
if (saanswers.length==1){
sa = sa + 1;
}
}
for (p=0;p<=12;p++){
displaycorrectanswers+="<br>"+msg1[p];
}
var msg ="Multiple Choice Mark: "+correctanswersno+"/"+mcquestions+" <br><br>Individual Marks: "+displaycorrectanswers+"<br>Short answer Mark"+sa;
displayMessage(msg);
}
for (s=1;s<=saquestions;s++){
var saanswers=("document.Questionform.sa"+s).match(shortanswers[s-1]);
if (saanswers.length==1){
sa = sa + 1;
}
}
Every loop it looks through an individual textbox and if a word matches the word in the array, shortanswers, then this word is put into another array called saanswers and if this array has length 1 e.g. a word has been matched then 1 is added to sa. However it doesnt seem to work. any ideas?
// Open a new window
var msgWindow = window.open('', 'Message');
// Write message in the new Window
msgWindow.document.write(text);
// Raise this window, in case it's not visible
msgWindow.focus();
}
//Enter total number of questions:
var totalquestions=31
var mcquestions=13
var saquestions=18
var correctchoices=new Array("a","a","b","c","b","c","a","a","b","c","a","b","b");
var correctanswers=new Array("memory locations","_ underscore","x=5+5;","20","Else","lose win","ticker = ticker + 1;","Ticker = ticker + 1;","300.000","Jonathon \b","var","var counter;","var mark = 50, 70");
var shortanswers=new Array("identifier","assignment","false","true","false","reverse of the boolean result","the variable will be once the line is executed","var","value","2","4","2","3","no semi colon","no space/between else and if","missing curly bracket/no curly bracket","need else instead of else if");
function gradeit(){
var actualchoices=new Array()
var msg1=new Array()
var correctanswersno=0
var t=0
var sa=0
var displaycorrectanswers=""
for (q=1;q<=mcquestions;q++){
var thequestion=eval("document.Questionform.q"+q)
for (c=0;c<thequestion.length;c++){
if (thequestion[c].checked==true)
actualchoices[q]=thequestion[c].value
}
if (actualchoices[q]==correctchoices[q]){
msg1[t]=q+")"+" Correct";
correctanswersno = correctanswersno + 1;
t = t + 1;
} else {
msg1[t]=q+")"+" Incorrect: <br>Correct Answer: "+correctchoices[q]+") "+correctanswers[q];
t = t + 1;
}
}
for (s=1;s<=saquestions;s++){
var saanswers=("document.Questionform.sa"+s).match(shortanswers[s-1]);
if (saanswers.length==1){
sa = sa + 1;
}
}
for (p=0;p<=12;p++){
displaycorrectanswers+="<br>"+msg1[p];
}
var msg ="Multiple Choice Mark: "+correctanswersno+"/"+mcquestions+" <br><br>Individual Marks: "+displaycorrectanswers+"<br>Short answer Mark"+sa;
displayMessage(msg);
}
for (s=1;s<=saquestions;s++){
var saanswers=("document.Questionform.sa"+s).match(shortanswers[s-1]);
if (saanswers.length==1){
sa = sa + 1;
}
}
Every loop it looks through an individual textbox and if a word matches the word in the array, shortanswers, then this word is put into another array called saanswers and if this array has length 1 e.g. a word has been matched then 1 is added to sa. However it doesnt seem to work. any ideas?