word/multichoice: skip imageless (unanswerable) questions
[sheet.git] / word / multichoice.js
1 class WordMultiChoice extends WordQuiz {
2         next() {
3                 let word = this.words.shift();
4                 if (!word[2]) return this.next();
5                 let form = put(this.form,
6                         '+img[src=$]+ul', `/data/word/en/${word[2]}.jpg`,
7                 );
8
9                 let answers = [word[0], this.words[0][0], this.words[1][0], this.words[2][0]]
10                         .shuffle()
11                 answers.forEach(suggest => {
12                         let label = suggest.replace(/\/.*/, '');
13                         let option = put(form, 'li', label, {onclick: () => {
14                                 if (suggest != word[0]) {
15                                         // incorrect
16                                         put(option, '.wrong');
17                                         return;
18                                 }
19                                 put(option, '.good');
20                                 window.setTimeout(() => this.next(), 500);
21                         }});
22                 });
23         }
24
25         setup() {
26                 this.form = document.getElementById('quiz');
27                 this.next();
28         }
29 };