word/quiz: report table to save user actions
[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                 if (!word[2]) return this.next();
6                 let form = put(this.form,
7                         '+img[src=$]+ul', `/data/word/32/${word[2]}.jpg`,
8                 );
9
10                 let answers = [word[0], this.words[0][0], this.words[1][0], this.words[2][0]]
11                         .shuffle()
12                 this.log('ask', word[2], answers);
13                 answers.forEach(suggest => {
14                         let label = suggest.replace(/\/.*/, '');
15                         let option = put(form, 'li', label, {onclick: () => {
16                                 this.log('pick', suggest, null, word[0]);
17                                 if (suggest != word[0]) {
18                                         // incorrect
19                                         put(option, '.wrong');
20                                         return;
21                                 }
22                                 put(option, '.good');
23                                 window.setTimeout(() => this.next(), 500);
24                         }});
25                 });
26         }
27
28         setup() {
29                 this.form = document.getElementById('quiz');
30                 this.next();
31         }
32 };