-
Notifications
You must be signed in to change notification settings - Fork 0
/
controller.js
49 lines (39 loc) · 1.29 KB
/
controller.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
import quizInfoView from "./view/quizInfoView";
import * as model from "./model";
import questionView from "./view/questionView";
import paginationView from "./view/paginationView";
const controlQuizInfo = async function (formData) {
try {
// set the formData in modal
await model.setQuestions(formData)
// toggle the quiz info and quiz question
quizInfoView.toggleQuizInfoAndQues();
// render question
questionView.render(model.getQuestionPerPage());
} catch (err) {
if (err) {
alert('some network problem please refresh the page or try later')
}
}
}
const controlQuestion = function (userPoint) {
// rendering right answer or wrong answer
questionView.renderRightAns();
// set user point
model.setUserPoint(userPoint)
// render pagitination
paginationView.render(model.state);
// render user point
questionView.displayingUserPoint(model.state)
}
const controlPagination = function (page) {
// render question
questionView.render(model.getQuestionPerPage(page));
}
// all handler here
const init = function () {
quizInfoView.addHandlerSubmit(controlQuizInfo);
questionView.addHandlerSubmit(controlQuestion);
paginationView.addHandler(controlPagination);
}
init();