Skip to content

Commit

Permalink
terms: add quiz question shuffling
Browse files Browse the repository at this point in the history
  • Loading branch information
taoky committed Oct 12, 2023
1 parent 59fb29b commit 2c07421
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions frontend/templates/terms.html
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ <h1>{{ obj.name }}</h1>
return;
}
const quizs = JSON.parse(ele.textContent);
// comment out this if you don't want to shuffle the quizs.
this.inplace_shuffle(quizs.questions);
this.quizs = quizs;
},
check() {
Expand All @@ -75,6 +77,18 @@ <h1>{{ obj.name }}</h1>
}
}
this.enable_submit = true;
},
inplace_shuffle(array) {
// https://stackoverflow.com/a/2450976/8460426
let current_index = array.length;
let random_index;

while (current_index > 0) {
random_index = Math.floor(Math.random() * current_index);
current_index--;

[array[current_index], array[random_index]] = [array[random_index], array[current_index]];
}
}
}
});
Expand Down

0 comments on commit 2c07421

Please sign in to comment.