word: language includes for general use
[sheet.git] / word / memory.js
index 0e523a1c7857fa7832abd14d6f180dd7a13ca27a..48e8b44cfb441ae2db57eba2b90482e8b19910f2 100644 (file)
@@ -1,4 +1,4 @@
-class WordMemory {
+class WordMemory extends WordQuiz {
        turn(click) {
                let target = click.currentTarget;
                if (!target.classList.contains('turn')) {
@@ -26,6 +26,9 @@ class WordMemory {
                        // lock both as correct
                        this.turned.forEach(card => put(card, '.good![onclick]'));
                        this.turned = [];
+                       if (Array.from(this.form.children).every(card => card.classList.contains('good'))) {
+                               put(this.form, '.good');
+                       }
                        return;
                }
 
@@ -34,7 +37,7 @@ class WordMemory {
                .forEach(card => put(card, '!.turn!.bad'));
        }
 
-       constructor() {
+       load(dataurl) {
                this.dataurl = '/data/wordpairs.json';
                fetch(this.dataurl).then(res => res.json()).then(pairs => {
                        this.turned = [];
@@ -42,7 +45,7 @@ class WordMemory {
                        this.form = document.getElementById('quiz');
                        this.cards = Object.entries(pairs).flat()
                                .map(e => e.toString())
-                               .sort(() => {return .5 - Math.random()}) // shuffle
+                               .shuffle()
                        this.cards.forEach(word => {
                                put(this.form,
                                        'figure>img[src=$]<', `/data/word/en/${word}.jpg`,
@@ -52,5 +55,3 @@ class WordMemory {
                });
        }
 };
-
-new WordMemory();