Fix duplicate practice answers

Fixe #3
This commit is contained in:
nora 2026-01-10 20:45:40 +01:00
parent 416f658e26
commit 4c02c9f137

View file

@ -1,19 +1,18 @@
const randomItem = (not) => {
let item;
do {
const idx = Math.floor(Math.random() * window.ITEMS.length);
item = window.ITEMS[idx];
} while (not && item === not);
return item;
};
const infoText = document.querySelector("#info-text");
function next() {
infoText.textContent = "";
const item = randomItem();
const candiates = [...window.ITEMS];
const nextRandomItem = () => {
const idx = Math.floor(Math.random() * candiates.length);
const result = candiates[idx];
candiates.splice(idx, 1);
return result;
};
const item = nextRandomItem();
const mangle = Math.random() > 0.5;
@ -24,10 +23,10 @@ function next() {
children[1].textContent = mangle ? item.means : item.mangle;
const options = [
randomItem(item),
randomItem(item),
randomItem(item),
randomItem(item),
nextRandomItem(item),
nextRandomItem(item),
nextRandomItem(item),
nextRandomItem(item),
];
const correctIdx = Math.floor(Math.random() * options.length);
options[correctIdx] = item;