X-Git-Url: http://git.shiar.nl/sheet.git/blobdiff_plain/7e9a11491faa8ff3f97c9a7fb855b238ad9ea85c..7bbf129e06d190145d0a4d9a7d4c7399d2112f88:/word/multichoice.js diff --git a/word/multichoice.js b/word/multichoice.js index b98842f..61a7b5a 100644 --- a/word/multichoice.js +++ b/word/multichoice.js @@ -1,16 +1,17 @@ -class Quiz { +class WordMultiChoice extends WordQuiz { next() { let word = this.words.shift(); + if (!word[2]) return this.next(); let form = put(this.form, - '+img[src=$]+ul', `/data/word/en/${word[0]}.jpg`, + '+img[src=$]+ul', `/data/word/en/${word[2]}.jpg`, ); - 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[0], this.words[0][0], this.words[1][0], this.words[2][0]] + .shuffle() answers.forEach(suggest => { let label = suggest.replace(/\/.*/, ''); let option = put(form, 'li', label, {onclick: () => { - if (suggest != word[2]) { + if (suggest != word[0]) { // incorrect put(option, '.wrong'); return; @@ -21,12 +22,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() { + this.form = document.getElementById('quiz'); + this.next(); } };