-
Notifications
You must be signed in to change notification settings - Fork 70
/
Copy pathquizModel.js
197 lines (161 loc) · 4.7 KB
/
quizModel.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
Quiz = function(){
var quiz = this;
this.addNewQuestion = function(val){
//check if the question already exists
if (quiz.questions == undefined){
quiz.questions = [];
}
for (var q in quiz.questions){
};
quiz.questions.push(val);
};
};
Quiz.convertToQuizObject = function(object){
if (object == undefined) return;
var quiz = new Quiz();
quiz._id = object._id;
quiz.title = object.title;
quiz.lessonID = object.lessonID;
quiz.questions = object.questions;
quiz.userAttempts = object.userAttempts;
return quiz;
};
Quiz.generateQuestion = function(questionType, quizId ){
var question = new Object();
question.quizId = quizId;
question.id = Random.id(); //assign an id to the question - need this for checking and validating answers
question.questionType = questionType;
//if the question type is true-or-false, populate the answer options
if (question.questionType == QuizOptions.TRUE_OR_FALSE){
question.optionTitles = [];
var trueOption = Quiz.generateAnswerOption("True", false, 0);
question.optionTitles.push(trueOption);
var falseOption = Quiz.generateAnswerOption("False", false, 1);
question.optionTitles.push(falseOption);
};
question.description = "";
question.title = "";
question.options = [];
return question;
};
Quiz.generateAnswerOption = function (title, isSelected, index){
var option = {};
option.title = title;
option.isSelected = isSelected;
option.index = index;
return option
}
Object.defineProperty(Quiz, "_title", {
get: function title(){
return this._title;
},
set: function title(val){
this._title = val;
}
});
Object.defineProperty(Quiz, "_questions", {
get: function question(){
return this._questions;
},
set: function questions(val){
this._questions = val;
}
});
Object.defineProperty(Quiz, "_lessonID", {
get: function lessonID(){
return this._lessonIDs
},
set: function lessonID(val){
this._lessonID = val;
}
});
Object.defineProperty(Quiz, "_userAttempts", { //an array of objects containig user ids, date and result
get: function userAttempts(){
return this._userAttempts;
},
set: function userAttempts(val){
this._userAttempts = val;
}
})
QuizOptions = {};
QuizOptions.MULTIPLE_CHOICE_SINGLE_ANSWER = "Multiple Choice - single answer";
QuizOptions.MULTIPLE_CHOICE_MULTIPLE_ANSWERS = "Multiple Choice - multiple answers";
QuizOptions.TRUE_OR_FALSE = "True or False";
QuizOptions.QUESTION_TYPES =
[ QuizOptions.MULTIPLE_CHOICE_SINGLE_ANSWER,
QuizOptions.MULTIPLE_CHOICE_MULTIPLE_ANSWERS,
QuizOptions.TRUE_OR_FALSE
];
QuizQuestion = function() {};
Object.defineProperty(QuizQuestion, "_questionType", {
get: function questionType() {
return this._quiztype;
},
set: function questionType(val) {
this._quiztype = val;
}
});
//array of lesson IDs - the quiz can be used in more than one lesson
Object.defineProperty(QuizQuestion, "_quizId", {
get: function quizId(){
return this._quizId
},
set: function quizId(val){
this._lessonIDs = val;
}
});
Object.defineProperty(QuizQuestion, "_title", {
get: function title(){
return this._title;
},
set: function title(val){
this._title = val;
}
});
Object.defineProperty(QuizQuestion, "_description", {
get: function description(){
return this._description;
},
set: function description(val){
this._description = val;
}
});
Object.defineProperty(QuizQuestion, "_options", {
get: function options(){
return this._options;
},
set: function options(val){
this._questions = val;
}
});
Object.defineProperty(QuizQuestion, "_saved",{
get: function saved(){
return this._saved;
},
set: function saved(val){
this._saved = val;
}
});
Object.defineProperty(QuizQuestion, "_answered", {
get: function answered(){
return this._answered;
},
set: function answered(val){
this._answered = val;
}
})
Object.defineProperty(QuizQuestion, "_isMultipleAnswer", {
get: function isMultipleAnswer(){
return this._questionType == QuizOptions.MULTIPLE_CHOICE_MULTIPLE_ANSWERS;
}
});
Object.defineProperty(QuizQuestion, "_isSingleAnswer", {
get: function isSingleAnswer(){
return this._questionType == QuizOptions.MULTIPLE_CHOICE_SINGLE_ANSWER;
}
});
Object.defineProperty(QuizQuestion, "_isTrueOrFalse", {
get: function isTrueOrfalse(){
return this._questionType == QuizOptions.TRUE_OR_FALSE;
}
})