// The Question constructor function
function Question(question, correctAnswer) {
var args = Question.arguments;
this.question = question;
this.correctAnswer = correctAnswer;
this.userAnswer = null;
this.isCorrect = isCorrect;
this.showForm = showForm;
this.userChoices = new Array();
for (var i = 0; i < args.length - 2; i++) {
this.userChoices[i] = args[i + 2];
}
}
// Method to determine if question is answered correctly
function isCorrect() {
if (this.correctAnswer == this.userAnswer) {
return true;
}
else {
return false;
}
}
// Method to display contents of Question object
function showForm(n) {
document.write('
' + (n + 1) + '. ' + this.question + '
');
}
// Function to correct the quiz and display score and correct answers
function correctQuiz() {
// Initialize correct and start correctPage string
var correct = 0;
var correctPage = 'Resultados del Examen
' +
'';
// Loop through Question objects, call isCorrect(), and count
// correct answers
for (var i = 0; i < quiz.length; i++) {
if (quiz[i].isCorrect()) {
correct++;
}
}
// Compute the score and add it to the correctPage string
var score = Math.round((correct / quiz.length) * 100);
correctPage += '
Calificación: ' + score + ' %
';
// If there are incorrect answers, list the correct ones
if (correct < quiz.length) {
correctPage += '
Estas son las respuestas a las preguntas ';
correctPage += 'que no ha contestado correctamente:
';
for (var i = 0; i < quiz.length; i++) {
if (!quiz[i].isCorrect()) {
correctPage += (i + 1) + '. ' +
quiz[i].userChoices[quiz[i].correctAnswer] + ' ';
}
}
}
else {
// Otherwise, offer congratulations
correctPage += '
¡Bien hecho!
';
}
// Finish correctPage, create a new window, and display correctPage
correctPage += '';
var correctWin = window.open('', '',
'height=200,width=300,scrollbars=yes');
correctWin.document.write(correctPage);
correctWin.document.close();
}
// Create four Question objects
var quiz = new Array();
quiz[0] = new Question(
"¿Cómo puede modificar las propiedades de un objeto?",
3, // Correct answer
"Seleccionarlo y oprimir el icono Properties", // Choice 0
"Seleccionarlo, dar clic secundario y elegir la opción Properties", // Choice 1
"Hacer Doble Clic sobre el objeto", // Choice 2
"Todas las anteriores"); // Choice 3
quiz[1] = new Question(
"Hacer Doble Clic sobre un objeto de texto le permite cambiar la capa a la que pertenece",
1,
"Sí",
"No",
"Sólo si está en la capa TEXTO",
"Sólo si dispone de 2 capas");
quiz[2] = new Question(
"Si usted elige una línea y un rectángulo y muestra las propiedades...",
0,
"Verá una lista limitada de propiedades",
"Verá todas las propiedades",
"Verá las propiedades del primer objeto que seleccionó",
"No verá ninguna propiedad");
quiz[3] = new Question(
"Cuando desea cerrar la Paleta de Propiedades, usted...",
2,
"Teclea CLOSE",
"La mueve fuera de la pantalla",
"Hace clic en la X ubicada en la parte superior de la paleta",
"Desactiva el objeto");