mirror of
https://github.com/Noratrieb/womangling.git
synced 2026-01-14 08:55:03 +01:00
parent
416f658e26
commit
4c02c9f137
1 changed files with 15 additions and 16 deletions
31
flashcard.js
31
flashcard.js
|
|
@ -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");
|
const infoText = document.querySelector("#info-text");
|
||||||
|
|
||||||
function next() {
|
function next() {
|
||||||
infoText.textContent = "";
|
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;
|
const mangle = Math.random() > 0.5;
|
||||||
|
|
||||||
|
|
@ -24,10 +23,10 @@ function next() {
|
||||||
children[1].textContent = mangle ? item.means : item.mangle;
|
children[1].textContent = mangle ? item.means : item.mangle;
|
||||||
|
|
||||||
const options = [
|
const options = [
|
||||||
randomItem(item),
|
nextRandomItem(item),
|
||||||
randomItem(item),
|
nextRandomItem(item),
|
||||||
randomItem(item),
|
nextRandomItem(item),
|
||||||
randomItem(item),
|
nextRandomItem(item),
|
||||||
];
|
];
|
||||||
const correctIdx = Math.floor(Math.random() * options.length);
|
const correctIdx = Math.floor(Math.random() * options.length);
|
||||||
options[correctIdx] = item;
|
options[correctIdx] = item;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue