mirror of
https://github.com/Noratrieb/womangling.git
synced 2026-01-14 17:05:04 +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");
|
||||
|
||||
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;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue