diff options
author | Frederick Yin <fkfd@fkfd.me> | 2022-04-18 14:57:50 +0800 |
---|---|---|
committer | Frederick Yin <fkfd@fkfd.me> | 2022-04-18 14:57:50 +0800 |
commit | 29aa3eac1900406decadf70f1d4cee15c13efd88 (patch) | |
tree | 12055e91e7e0f7aa16d7dee572228ec832a40ec9 | |
parent | d6ba1fa610740a7ea0ba07256bf525766971d86a (diff) |
Remove word from list once shown
-rw-r--r-- | index.js | 12 |
1 files changed, 7 insertions, 5 deletions
@@ -15,15 +15,17 @@ let currentWord = {}; let hintTaken = false; function newWord() { - const word = WORDS[Math.floor(Math.random() * WORDS.length)]; + const idx = Math.floor(Math.random() * WORDS.length); + currentWord = WORDS[idx]; + WORDS.splice(idx, 1); // remove word from WORDS so it will not show again + for (let album in ALBUMS) { - if (ALBUMS[album].tracks.includes(word.track)) { - word.album = album; + if (ALBUMS[album].tracks.includes(currentWord.track)) { + currentWord.album = album; } } - currentWord = word; - wordElem.innerHTML = word["word"]; + wordElem.innerHTML = currentWord.word; hintTaken = false; // clean after the mess |