|
1 | 1 | function toggleModal() { |
2 | 2 | event.stopPropagation(); |
3 | | - let modal_container = $("#add-modal"); |
4 | | - modal_container.toggle(); |
| 3 | + let modal_container = $("#add-modal"); modal_container.toggle(); |
5 | 4 | } |
6 | 5 |
|
7 | 6 | function closeModal() { |
@@ -135,139 +134,36 @@ function quizHandler(name) { |
135 | 134 |
|
136 | 135 | let obj = quizJson[index]; |
137 | 136 |
|
138 | | - let question = `${index+1}.${obj.question}`; |
139 | | - let answer = obj.answer; |
140 | | - let difficulty = obj.difficulty; |
141 | | - let length = quizJson.length; |
| 137 | + function spawnNextBtn() { |
| 138 | + $("#quiz-window").append(` |
| 139 | + <button id="next-btn" class="next-btn">Skip</button> |
| 140 | + `) |
| 141 | + $("#next-btn").on("click", function() { |
| 142 | + index++; |
| 143 | + generateQuizQuestion(); |
| 144 | + }); |
| 145 | + } |
142 | 146 |
|
143 | 147 | switch (obj.type) { |
144 | 148 | case "flashcard": |
145 | | - $("#quiz-window").html(` |
146 | | - <b class="difficulty-indicator ${difficulty}">${difficulty}</b> |
147 | | - <b class="question-counter">${index+1}/${length}</b> |
148 | | - <h2 id="content">${question}</h2> |
149 | | - <button class="btn" id="reveal-btn">Reveal</button> |
150 | | - <button id="next-btn" class="next-btn">Skip</button> |
151 | | - `); |
152 | | - |
153 | | - $("#reveal-btn").on("click", function(event) { |
154 | | - if ($(this).text() === "Reveal") { |
155 | | - $("#content").text(answer); |
156 | | - $(this).text("Back"); |
157 | | - $("#next-btn").text("Next →"); |
158 | | - } else { |
159 | | - $("#content").text(question); |
160 | | - $(this).text("Reveal"); |
161 | | - $("#next-btn").text("Skip"); |
162 | | - }; |
163 | | - }); |
164 | | - |
165 | | - $("#next-btn").on("click", function() { |
166 | | - index++; |
167 | | - generateQuizQuestion(); |
168 | | - }); |
| 149 | + genFlashcard(quizJson, index); |
| 150 | + spawnNextBtn(); |
169 | 151 | break; |
170 | 152 |
|
171 | 153 | case "one-line": |
172 | | - $("#quiz-window").html(` |
173 | | - <b class="difficulty-indicator ${difficulty}">${difficulty}</b> |
174 | | - <b class="question-counter">${index+1}/${length}</b> |
175 | | - <h2>${question}</h2> |
176 | | - <input type = "text" id = "quiz-input" placeholder = "Provide answer here..."> |
177 | | - <button class="btn" id="reveal-btn">Reveal</button> |
178 | | - <button id="next-btn" class="next-btn">Skip</button> |
179 | | - `);//NOTE: Make it button with |
180 | | - let quiz_input = $("#quiz-input") |
181 | | - |
182 | | - $("#reveal-btn").on("click", function() { |
183 | | - quiz_input.prop("placeholder",answer); |
184 | | - }); |
185 | | - |
186 | | - quiz_input.on("change", function() { |
187 | | - if (quiz_input.val() === answer) { |
188 | | - quiz_input.css("border-color", "green"); |
189 | | - quiz_input.css("box-shadow", "0 0 5px rgba(0, 255, 0, 0.9"); |
190 | | - $("#next-btn").text("Next →"); |
191 | | - }else if (quiz_input.val() === "") { |
192 | | - quiz_input.removeAttr("style"); |
193 | | - }else { |
194 | | - quiz_input.css("border-color", "red"); |
195 | | - quiz_input.css("box-shadow", "0 0 5px rgba(255, 0, 0, 0.9)"); |
196 | | - $("#next-btn").text("Skip"); |
197 | | - }; |
198 | | - }); |
199 | | - |
200 | | - $("#next-btn").on("click", function() { |
201 | | - index++; |
202 | | - generateQuizQuestion(); |
203 | | - }); |
| 154 | + genOneLine(quizJson, index); |
| 155 | + spawnNextBtn(); |
204 | 156 | break; |
205 | 157 | case "true/false": |
206 | | - $("#quiz-window").html(` |
207 | | - <b class="difficulty-indicator ${difficulty}">${difficulty}</b> |
208 | | - <b class="question-counter">${index+1}/${length}</b> |
209 | | - <h2>${question}</h2> |
210 | | - <div class="tf-container"> |
211 | | - <button class="tf-btn true-btn" id="true-btn">True</button> |
212 | | - <button class="tf-btn false-btn" id="false-btn">False</button> |
213 | | - </div> |
214 | | - <button id="next-btn" class="next-btn">Skip</button> |
215 | | - `);//NOTE: Make it button with |
216 | | - |
217 | | - if (answer === true) { |
218 | | - $("#true-btn").on("click", function() { |
219 | | - $("#next-btn").text("Next →"); |
220 | | - $("#false-btn").addClass("disabled"); |
221 | | - }); |
222 | | - } else if (answer === false) { |
223 | | - $("#false-btn").on("click", function() { |
224 | | - $("#next-btn").text("Next →"); |
225 | | - $("#false-btn").addClass("disabled"); |
226 | | - }); |
227 | | - } else { |
228 | | - alert(`Answer format in question with index: ${index} is incorrect.`); |
229 | | - index++; |
230 | | - generateQuizQuestion(); |
231 | | - }; |
232 | | - $("#next-btn").on("click", function() { |
233 | | - index++; |
234 | | - generateQuizQuestion(); |
235 | | - }); |
| 158 | + genTrueFalse(quizJson, index); |
| 159 | + spawnNextBtn(); |
236 | 160 | break; |
237 | 161 | case "multiple-choice": |
238 | | - $("#quiz-window").html(` |
239 | | - <b class="difficulty-indicator ${difficulty}">${difficulty}</b> |
240 | | - <b class="question-counter">${index+1}/${length}</b> |
241 | | - <h2>${question}</h2> |
242 | | - <div id="mch-container" class="mch-container"> |
243 | | - </div> |
244 | | - <button id="next-btn" class="next-btn">Skip</button> |
245 | | - `); |
246 | | - |
247 | | - obj.choices.forEach(function(choice, index) { |
248 | | - let dict = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; |
249 | | - let letter = dict[index]; |
250 | | - $("#mch-container").append(`<button id="${letter}-btn">${letter}.${choice}</button>`); |
251 | | - |
252 | | - if (choice === obj.answer) { |
253 | | - $(`#${letter}-btn`).on("click", function() { |
254 | | - $(this).css("background-color", "#2BE028"); |
255 | | - $("#next-btn").text("Next →"); |
256 | | - }); |
257 | | - }else { |
258 | | - $(`#${letter}-btn`).on("click", function() { |
259 | | - $(this).css("background-color", "#FC2E05"); |
260 | | - }); |
261 | | - }; |
262 | | - }); |
263 | | - |
264 | | - $("#next-btn").on("click", function() { |
265 | | - index++; |
266 | | - generateQuizQuestion(); |
267 | | - }); |
| 162 | + genMultipleChoice(quizJson, index); |
| 163 | + spawnNextBtn(); |
268 | 164 | break; |
269 | 165 | default: |
270 | | - alert(`Type '${obj.type}' is not supported`); //NOTE: Skipping... |
| 166 | + alert(`Type '${obj.type}' is not supported`); |
271 | 167 | index++; |
272 | 168 | generateQuizQuestion(); |
273 | 169 | }; |
|
0 commit comments