word/quiz: preset configuration filters level
authorMischa POSLAWSKY <perl@shiar.org>
Thu, 30 Dec 2021 00:40:43 +0000 (01:40 +0100)
committerMischa POSLAWSKY <perl@shiar.org>
Fri, 31 Dec 2021 04:29:05 +0000 (05:29 +0100)
Manual option preset.cat to test difficulty selection.

word/quiz.js

index 361d075e66391f517b08b8f51f7a12222ef9b954..146aff73e61171c10f81779aad8be30777d7da35 100644 (file)
@@ -8,11 +8,16 @@ Array.prototype.shuffle = function () {
 
 class WordQuiz {
        dataselect(json) {
 
 class WordQuiz {
        dataselect(json) {
+               // find viable rows from json data
                let rows = Object.values(json);
                let rows = Object.values(json);
+               if (this.preset.level !== undefined) {
+                       rows = rows.filter(row => row[1] <= this.preset.level);
+               }
                return rows.shuffle();
        }
 
        load(dataurl) {
                return rows.shuffle();
        }
 
        load(dataurl) {
+               this.preset = {};
                fetch(dataurl).then(res => res.json()).then(json => {
                        this.words = this.dataselect(json)
                        this.setup();
                fetch(dataurl).then(res => res.json()).then(json => {
                        this.words = this.dataselect(json)
                        this.setup();