index: release v1.18 with only altgr index linked
[sheet.git] / word / multichoice.js
1 class WordMultichoice extends WordQuiz {
2         next() {
3                 if (this.words.length < 4) return;
4                 let word = this.words.shift();
5                 let form = put(this.form,
6                         '+img[src=$]+ul', word.thumb()
7                 );
8
9                 let answers = [word, this.words[0], this.words[1], this.words[2]]
10                         .shuffle()
11                 this.log('ask', word.id, answers.map(w => w.id));
12                 answers.forEach(suggest => {
13                         let option = put(form, 'li', suggest.label, {onclick: () => {
14                                 this.log('pick', suggest.id, null, word.id);
15                                 if (suggest.label != word.label) {
16                                         // incorrect
17                                         put(option, '.wrong');
18                                         return;
19                                 }
20                                 put(option, '.good');
21                                 window.setTimeout(() => this.next(), 500);
22                         }});
23                 });
24         }
25
26         setup() {
27                 super.setup();
28                 this.next();
29         }
30 };