word: language includes for general use
[sheet.git] / word / memory.js
index c3adfd4590d3d7dd6e4edc519620a84b8442b78f..48e8b44cfb441ae2db57eba2b90482e8b19910f2 100644 (file)
@@ -1,4 +1,4 @@
-class WordMemory {
+class WordMemory extends WordQuiz {
        turn(click) {
                let target = click.currentTarget;
                if (!target.classList.contains('turn')) {
@@ -37,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 = [];
@@ -45,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`,
@@ -55,5 +55,3 @@ class WordMemory {
                });
        }
 };
-
-new WordMemory();