Last active
December 9, 2015 23:13
-
-
Save matthamil/9c097ddd62e66d314b0d to your computer and use it in GitHub Desktop.
This file contains 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
// Question Module | |
// Modules inheriting from Question: | |
// Likert, YesNo, Gender, Age | |
var Question = function(question, type, answerChoices){ | |
var text = question || ''; | |
var questionType = type || ''; | |
var answers = answerChoices || []; | |
return { | |
getQuestion: function () { | |
return text; | |
}, | |
getQuestionType: function() { | |
return questionType; | |
}, | |
getAnswerChoices: function () { | |
return answers; | |
}, | |
getRandomAnswer: function () { | |
var randomNum = Math.floor(Math.random() * (answers.length - 1)) + 1; | |
return answers[randomNum] || "Question not defined."; | |
}, | |
printQuestion: function(){ | |
return ("Question: " + text + "\n" + | |
"Type: " + questionType + "\n" + | |
"Answer Choices: " + answers + "\n" + | |
"Your choice: " + this.getRandomAnswer()); | |
} | |
}; | |
}; | |
var YesNo = function(question){ | |
Question.call(this, question, "Yes/No", ["Yes", "No"]); | |
}; | |
YesNo.prototype = new Question(); | |
var test = new YesNo("Do you own a cat?"); | |
console.log(test.printQuestion()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment