|
| 1 | +Quiz = function(){ |
| 2 | + var quiz = this; |
| 3 | + this.addNewQuestion = function(val){ |
| 4 | + //check if the question already exists |
| 5 | + if (quiz.questions == undefined){ |
| 6 | + quiz.questions = []; |
| 7 | + } |
| 8 | + for (var q in quiz.questions){ |
| 9 | + |
| 10 | + }; |
| 11 | + |
| 12 | + quiz.questions.push(val); |
| 13 | + }; |
| 14 | + |
| 15 | +}; |
| 16 | + |
| 17 | +Quiz.convertToQuizObject = function(object){ |
| 18 | + |
| 19 | + if (object == undefined) return; |
| 20 | + var quiz = new Quiz(); |
| 21 | + |
| 22 | + quiz._id = object._id; |
| 23 | + quiz.title = object.title; |
| 24 | + quiz.lessonID = object.lessonID; |
| 25 | + quiz.questions = object.questions; |
| 26 | + quiz.userAttempts = object.userAttempts; |
| 27 | + |
| 28 | + return quiz; |
| 29 | +}; |
| 30 | + |
| 31 | + |
| 32 | +Object.defineProperty(Quiz, "_title", { |
| 33 | + get: function title(){ |
| 34 | + return this._title; |
| 35 | + }, |
| 36 | + set: function title(val){ |
| 37 | + this._title = val; |
| 38 | + } |
| 39 | +}); |
| 40 | +Object.defineProperty(Quiz, "_questions", { |
| 41 | + get: function question(){ |
| 42 | + return this._questions; |
| 43 | + }, |
| 44 | + set: function questions(val){ |
| 45 | + this._questions = val; |
| 46 | + } |
| 47 | +}); |
| 48 | + |
| 49 | +Object.defineProperty(Quiz, "_lessonID", { |
| 50 | + get: function lessonID(){ |
| 51 | + return this._lessonIDs |
| 52 | + }, |
| 53 | + set: function lessonID(val){ |
| 54 | + this._lessonID = val; |
| 55 | + } |
| 56 | +}); |
| 57 | + |
| 58 | +Object.defineProperty(Quiz, "_userAttempts", { //an array of objects containig user ids, date and result |
| 59 | + get: function userAttempts(){ |
| 60 | + return this._userAttempts; |
| 61 | + }, |
| 62 | + set: function userAttempts(val){ |
| 63 | + this._userAttempts = val; |
| 64 | + } |
| 65 | +}) |
| 66 | + |
| 67 | + |
| 68 | + |
| 69 | + |
| 70 | +QuizOptions = {}; |
| 71 | + |
| 72 | +QuizOptions.MULTIPLE_CHOICE_SINGLE_ANSWER = "Multiple Choice - single answer"; |
| 73 | +QuizOptions.MULTIPLE_CHOICE_MULTIPLE_ANSWERS = "Multiple Choice - multiple answers"; |
| 74 | +QuizOptions.TRUE_OR_FALSE = "True or False"; |
| 75 | +QuizOptions.QUESTION_TYPES = |
| 76 | + [ QuizOptions.MULTIPLE_CHOICE_SINGLE_ANSWER, |
| 77 | + QuizOptions.MULTIPLE_CHOICE_MULTIPLE_ANSWERS, |
| 78 | + QuizOptions.TRUE_OR_FALSE |
| 79 | + ]; |
| 80 | + |
| 81 | + |
| 82 | + |
| 83 | +QuizQuestion = function(){}; |
| 84 | +Object.defineProperty(QuizQuestion, "_questionType", { |
| 85 | + get: function questionType() { |
| 86 | + return this._quiztype; |
| 87 | + }, |
| 88 | + set: function questionType(val) { |
| 89 | + this._quiztype = val; |
| 90 | + } |
| 91 | +}); |
| 92 | + |
| 93 | +//array of lesson IDs - the quiz can be used in more than one lesson |
| 94 | +Object.defineProperty(QuizQuestion, "_quizId", { |
| 95 | + get: function quizId(){ |
| 96 | + return this._quizId |
| 97 | + }, |
| 98 | + set: function quizId(val){ |
| 99 | + this._lessonIDs = val; |
| 100 | + } |
| 101 | +}); |
| 102 | + |
| 103 | +Object.defineProperty(QuizQuestion, "_title", { |
| 104 | + get: function title(){ |
| 105 | + return this._title; |
| 106 | + }, |
| 107 | + set: function title(val){ |
| 108 | + this._title = val; |
| 109 | + } |
| 110 | +}); |
| 111 | + |
| 112 | +Object.defineProperty(QuizQuestion, "_description", { |
| 113 | + get: function description(){ |
| 114 | + return this._description; |
| 115 | + }, |
| 116 | + set: function description(val){ |
| 117 | + this._description = val; |
| 118 | + } |
| 119 | +}); |
| 120 | + |
| 121 | +Object.defineProperty(QuizQuestion, "_options", { |
| 122 | + get: function options(){ |
| 123 | + return this._options; |
| 124 | + }, |
| 125 | + set: function options(val){ |
| 126 | + this._questions = val; |
| 127 | + } |
| 128 | +}); |
| 129 | + |
| 130 | +Object.defineProperty(QuizQuestion, "_saved",{ |
| 131 | + get: function saved(){ |
| 132 | + return this._saved; |
| 133 | + }, |
| 134 | + set: function saved(val){ |
| 135 | + this._saved = val; |
| 136 | + } |
| 137 | +}); |
| 138 | + |
| 139 | +Object.defineProperty(QuizQuestion, "_answered", { |
| 140 | + get: function answered(){ |
| 141 | + return this._answered; |
| 142 | + }, |
| 143 | + set: function answered(val){ |
| 144 | + this._answered = val; |
| 145 | + } |
| 146 | +}) |
| 147 | + |
| 148 | +Object.defineProperty(QuizQuestion, "_isMultipleAnswer", { |
| 149 | + get: function isMultipleAnswer(){ |
| 150 | + return this._questionType == QuizOptions.MULTIPLE_CHOICE_MULTIPLE_ANSWERS; |
| 151 | + } |
| 152 | +}); |
| 153 | + |
| 154 | +Object.defineProperty(QuizQuestion, "_isSingleAnswer", { |
| 155 | + get: function isSingleAnswer(){ |
| 156 | + return this._questionType == QuizOptions.MULTIPLE_CHOICE_SINGLE_ANSWER; |
| 157 | + } |
| 158 | +}); |
| 159 | + |
| 160 | +Object.defineProperty(QuizQuestion, "_isTrueOrFalse", { |
| 161 | + get: function isTrueOrfalse(){ |
| 162 | + return this._questionType == QuizOptions.TRUE_OR_FALSE; |
| 163 | + } |
| 164 | +}) |
| 165 | + |
| 166 | + |
0 commit comments