mmasci
01-28-2003, 05:36 AM
I have developed a set of 8 DW CourseBuilder multiple choice questions.
What I want to do is create a function that will score the result of all 8 questions.
Below is what I have already put together...
var gotCorrect = new Array(8);
function setCorrect(index)
{
gotCorrect[index] = 1;
}
function showScore()
{
var score = 0;
var msg = "";
// Add up score
for (i=0; i < gotCorrect.length; i++) {
if (gotCorrect[i] == 1) {
score++;
}
}
if (score >= 5)
msg += "You have gained a solid understanding of \nleadership styles and where it is appropriate to use \nautocratic, democratic and laissez faire leadership. \n\n";
if (score < 6)
msg += "A review of the various leadership styles \nwould be useful to gain a better understanding of how \nto identify which leadership style is necessary in your \nwork group. \n\n";
msg = "Your score is: "+score+" out of 8\n\n" + msg;
alert(msg);
}
Here is the button code that I have inserted at the end of the DW CourseBuilder questions that contains the event handler.
<a href="javascript:showScore();"><img src="images/btn_score.gif" width="100" height="25" border="0"></a>
The message part is working fine when I click the button, but I cant seem to get the scoring part to work.
Cheers,
mmasci
What I want to do is create a function that will score the result of all 8 questions.
Below is what I have already put together...
var gotCorrect = new Array(8);
function setCorrect(index)
{
gotCorrect[index] = 1;
}
function showScore()
{
var score = 0;
var msg = "";
// Add up score
for (i=0; i < gotCorrect.length; i++) {
if (gotCorrect[i] == 1) {
score++;
}
}
if (score >= 5)
msg += "You have gained a solid understanding of \nleadership styles and where it is appropriate to use \nautocratic, democratic and laissez faire leadership. \n\n";
if (score < 6)
msg += "A review of the various leadership styles \nwould be useful to gain a better understanding of how \nto identify which leadership style is necessary in your \nwork group. \n\n";
msg = "Your score is: "+score+" out of 8\n\n" + msg;
alert(msg);
}
Here is the button code that I have inserted at the end of the DW CourseBuilder questions that contains the event handler.
<a href="javascript:showScore();"><img src="images/btn_score.gif" width="100" height="25" border="0"></a>
The message part is working fine when I click the button, but I cant seem to get the scoring part to work.
Cheers,
mmasci