Created
April 27, 2010 21:21
-
-
Save weatheredwatcher/381353 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Question(questionType, questionText, questionChoices, questionAnswers, answers){ | |
this.questionType = questionType; | |
this.questionText = questionText; | |
this.questionChoices = questionChoices.split("|"); | |
this.questionAnswers = questionAnswers.split(","); | |
this.answers = answers; | |
} | |
Question.prototype.checkAnswer = function(){ | |
var myAnswers = []; | |
for(var i=0; i<document.answers.answer.length; ++i){ | |
if(document.answers.answer[i].checked){ | |
myAnswers.push(i); | |
} | |
} | |
if(this.questionAnswers.toString() == myAnswers.toString()){ | |
alert("true"); | |
}else { | |
alert("false"); | |
} | |
//alert("Guesses:"+ myAnswers + "Answers:" + this.questionAnswers); | |
} | |
Question.prototype.displayQuestion = function(){ | |
myHTMLOutput = "<h4>" + this.questionText + "</h4><form name='answers'>"; | |
for ( var i=0, len=this.questionChoices.length; i<len; ++i ){ | |
myHTMLOutput += '<input type="checkbox" name="answer" value="' + i + '" />' + this.questionChoices[i] + "<br />"; | |
} | |
myHTMLOutput += '<input type="button" value="Check" onClick="myQuestion.checkAnswer()" />'; | |
document.write(myHTMLOutput); | |
} | |
var myQuestion = new Question(2,"What was the question again?", "My,What Big teeth you have!|You|Us|Them", "0,2,3"); | |
myQuestion.displayQuestion(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment