1. Interfaccia utente. E' il test che si vede mostrato l'utente con domande, una frase di rapida spiegazione di come devono essere le risposte (una tra le alternative proposte, piu' di una con peso o non e simili), campi per le risposte: la videata che viene prodotta dal browser.
2. Modello del test.
function showForm(n)
{ document.write((n + 1) + '. ' + this.question +
'<BLOCKQUOTE><FORM>');
for (var i = 0; i < this.userChoices.length;
i++) {
document.write('<INPUT
TYPE = "RADIO" NAME = "q' + n +
'" onClick = "quiz[' + n + '].userAnswer = ' + i + ';">');
document.write(this.userChoices[i]
+ '<BR>');
}
document.write('</FORM></BLOCKQUOTE>');
}
quiz[1] = new makeQuestion("What is the difference between a method
and a function?", // 2nd
question
0,
// correct answer
"a method is tied to an object", // choice 0
"a method\'s name isn't followed by parentheses",
// choice 1
"a function
doesn't contain any variables", //choice 2
"a function must be passed parameters");
quiz[2] = new makeQuestion("Which object does the document object branch
off of in the JavaScript tree?",
3,
"the forms object",
"the navigator object",
"the window object",
"it doesn\'t branch off an object");
quiz[3] = new makeQuestion("Which of the following browsers does not
support JavaScript?",
3,
"Internet Explorer 3.01 for Windows 95",
"Navigator 2.0 for UNIX",
"Internet Explorer 3.0 for the Mac",
"Navigator 2.02 for OS2 Warp");
3. Applicazione realizzata.
// Function to correct the quiz and display score, correct answers.
function correctQuiz() {
var correct = 0;
correctPage = '<HTML><TITLE>Corrections</TITLE><BODY BGCOLOR
= "#FFFFFF">';
for (var i = 0; i < quiz.length; i++) {
if (quiz[i].isCorrect()) correct++;
}
var score = Math.round((correct / quiz.length) * 100);
correctPage += 'Score: <STRONG>' + score + '</STRONG> %';
if (correct < quiz.length) {
correctPage += ifWrong;
for (var i = 0; i < quiz.length;
i++) {
if (!quiz[i].isCorrect()) {
correctPage += (i + 1) + '. ' +
quiz[i].userChoices[quiz[i].correctAnswer] + '<BR>';
}
}
}
else correctPage += ifAced;
correctPage += '</BODY></HTML>';
correctwin = window.open ('', '', 'height=300,width=300,scrollbars=yes');
if (correctwin.opener == null) correctwin.opener
= window;
correctwin.location = 'javascript:opener.correctPage';
}
// Message to display if quiz is aced.
var ifAced = "<P>Well done, you aced it.<P>";
// Message to display if any are wrong.
var ifWrong = "<P>Here are the correct answers to the questions
you got wrong:<P>";
................................................
// BUG FIX: In Netscape 3 and greater, forms are
not reset on reload.
// This for loop is used to automatically reset
the quiz forms if the
// user reloads the page. If not for this fix, whenever
the quiz is
// reloaded, the radio button choices on the page
stay the same but
// the user's choices in the memory will be reset.
This means
// the choices on the page are different than the
ones in memory!
if (navigator.appName == "Netscape" &&
parseInt(navigator.appVersion)
>= 3) {
for (var i = 0; i < document.forms.length;
i++) {
document.forms[i].reset();
}
}
//-->
</SCRIPT>
<!-- This link (or button) runs the correctQuiz() function when
clicked. -->
<A HREF = "javascript:correctQuiz()">Correct Quiz</A>
4.Codice completo dove e' evidenziata la parte dipendente
dal caso specifico: si veda il link negli Esempio presentati a lezione.