I have a Java Script quiz I downloaded for a basic website, but I get some errors in IE but not in Chrome. How can I prevent these errors because all my users will use IE?
function showWrongAnswer(){
document.id('error').set('html', 'Wrong answer, Please try again');
}
function showScore() {
var score = quizMaker.getScore();
var el = new Element('h3');
el.set('html', 'Thank you!');
document.id('result').adopt(el);
el = new Element('h4');
el.set('html', 'Score: ' + score.numCorrectAnswers + ' of ' + score.numQuestions);
document.id('result').adopt(el);
if(score.incorrectAnswers.length > 0) {
el = new Element('h4');
el.set('html', 'Incorrect answers:');
document.id('result').adopt(el);
for(var i=0;i<score.incorrectAnswers.length;i++) {
var incorrectAnswer = score.incorrectAnswers[i];
el = new Element('div');
el.set('html', '<b>' + incorrectAnswer.questionNumber + ': ' + incorrectAnswer.label + '</b>');
document.id('result').adopt(el);
el = new Element('div');
el.set('html', 'Correct answer : ' + incorrectAnswer.correctAnswer);
document.id('result').adopt(el);
el = new Element('div');
el.set('html', 'Your answer : ' + incorrectAnswer.userAnswer);
document.id('result').adopt(el);
}
}
}
var questions = [
{
label : 'What is the last step when entering an admission?',
options : ['Assign bed', 'Enter resident name and date of birth', 'Assign organization','None of the above'],
answer : ['Assign bed'],
forceAnswer : true
},
{
label : 'What widget is used to enter new admissions?',
options : ['Favorites', 'Recent Admissions', 'Processes','None of the above'],
answer : ['Processes']
},
]
function showAnswerAlert() {
document.id('error').set('html', 'You have to answer before you continue to the next question');
}
function clearErrorBox() {
document.id('error').set('html','');
}
var quizMaker = new DG.QuizMaker({
questions : questions,
el : 'questions',
forceCorrectAnswer:false,
listeners : {
'finish' : showScore,
'missinganswer' : showAnswerAlert,
'sendanswer' : clearErrorBox,
'wrongAnswer' : showWrongAnswer
}
});
quizMaker.start();
_addQuestionElement : function() {
var el = new Element('div');
el.addClass('dg-question-label');
el.set('html', this._getCurrentQuestion().label);
document.id(this.html.el).adopt(el);
},
_addAnsweringOptions : function() {
var currentQuestion = this._getCurrentQuestion();
var options = currentQuestion.options;
var isMulti = currentQuestion.answer.length > 1;
for(var i=0;i<options.length;i++) {
var el = new Element('div');
el.addClass('dg-question-option');
var option = options[i];
var id = 'dg-quiz-option-' + this.internal.questionIndex + '-' + i;
var checkbox = new Element('input', {
name : 'dg-quiz-options',
id : id,
type : isMulti ? 'checkbox' : 'radio',
value : option
});
el.adopt(checkbox);
var label = new Element('label', { 'for' : id, 'html' : option });
el.adopt(label);
document.id(this.html.el).adopt(el);
}
},
_addAnswerButton : function() {
var el = new Element('div');
el.addClass('dg-answer-button-container');
var button = new Element('input');
button.type = 'button';
button.set('value', this.internal.labelAnswerButton);
button.addEvent('click', this._sendAnswer.bind(this));
el.adopt(button);
document.id(this.html.el).adopt(el);
},
_sendAnswer : function() {
var answer = this._getAnswersFromForm();
_getAnswersFromForm : function() {
var ret = [];
var els = document.id(this.html.el).getElements('input');
for(var i=0;i<els.length;i++) {
if(els[i].checked) {
ret.push( {
index : i,
answer : els[i].value
});
}
}
return ret;
},
_clearEl : function () {
document.id(this.html.el).set('html','');
},