word: common language handling in quiz
[sheet.git] / word / quiz.js
index ef5e0d84735c1f41565916d10db7080306a878ca..0518fa14bdbc72c386f1b5abe4554c1f05d30965 100644 (file)
@@ -8,7 +8,8 @@ class Quiz {
                let answers = [word[2], this.words[1][2], this.words[2][2], this.words[3][2]]
                        .sort(() => {return .5 - Math.random()}) // shuffle
                answers.forEach(suggest => {
-                       let option = put(form, 'li', suggest, {onclick: () => {
+                       let label = suggest.replace(/\/.*/, '');
+                       let option = put(form, 'li', label, {onclick: () => {
                                if (suggest != word[2]) {
                                        // incorrect
                                        put(option, '.wrong');
@@ -20,9 +21,8 @@ class Quiz {
                });
        }
 
-       constructor() {
-               this.dataurl = '/data/wordlist.nl.json';
-               fetch(this.dataurl).then(res => res.json()).then(json => {
+       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
@@ -31,5 +31,3 @@ class Quiz {
                });
        }
 };
-
-new Quiz();