So...basically I wanted to program a vocabulary trainer.
I stored all words in a dictionary (and don't spam the comments with "This is not a JSON", i know), the key was the English word, the value was the German/French word. I wanted that in the vocabulary test, he asked a random word and I had to put the translation in the input bar below, then you press check and it checked it.
I also wanted that the asked word could be an English (Key) or a German (Value) word.
So I wanted that it uses a key or a value.
DISCLAIMER: This is not a duplicate! There was no question on this forum that helped me!
Here is the JS function to generate a random new Word:
function nextWord() {
const AttemptInput = document.querySelector("#input")
AttemptInput.value = '' //The input field gets cleared at the beginning
let ObjKeys = Object.keys(Vocab) // I get all the Keys of my Vocab dictionary
RandomKey = ObjKeys[Math.floor(Math.random() * ObjKeys.length)] // He gets a random key so a random word from the dict
WordLabel.innerHTML = `${RandomKey}?`; // He puts the Vocabulary as a text into a textlabel and adds a question mark
}
On load of the test page it runs that function
Now it only asks English words but i wanted to use english and german words. So in the addVocab() function I just added a new line that also adds the german word as a key and the english word as value. But that didnt work that well...I also tried to use Object.entries but like Object.values and Key.value didn't work....now I hope that somebody can help me...