X-Git-Url: http://git.shiar.net/sheet.git/blobdiff_plain/7e9a11491faa8ff3f97c9a7fb855b238ad9ea85c..e5a6d30b2cf44f7791d2cef79f8d08da3891f79d:/word/multichoice.js diff --git a/word/multichoice.js b/word/multichoice.js index b98842f..300a32f 100644 --- a/word/multichoice.js +++ b/word/multichoice.js @@ -1,16 +1,18 @@ -class Quiz { +class WordMultichoice extends WordQuiz { next() { + if (this.words.length < 4) return; let word = this.words.shift(); let form = put(this.form, - '+img[src=$]+ul', `/data/word/en/${word[0]}.jpg`, + '+img[src=$]+ul', word.thumb() ); - let answers = [word[2], this.words[1][2], this.words[2][2], this.words[3][2]] - .sort(() => {return .5 - Math.random()}) // shuffle + let answers = [word, this.words[0], this.words[1], this.words[2]] + .shuffle() + this.log('ask', word.id, answers.map(w => w.id)); answers.forEach(suggest => { - let label = suggest.replace(/\/.*/, ''); - let option = put(form, 'li', label, {onclick: () => { - if (suggest != word[2]) { + let option = put(form, 'li', suggest.label, {onclick: () => { + this.log('pick', suggest.id, null, word.id); + if (suggest.label != word.label) { // incorrect put(option, '.wrong'); return; @@ -21,12 +23,8 @@ class Quiz { }); } - constructor(dataurl) { - fetch(dataurl).then(res => res.json()).then(json => { - this.form = document.getElementById('quiz'); - this.words = Object.values(json) - .sort(() => {return .5 - Math.random()}) // shuffle - this.next(); - }); + setup() { + super.setup(); + this.next(); } };