0
Why this JavaScript doesn't translate words from input, please help me.
2 Answers
+ 2
1. input_text should be the source, not the target
2. Iterate through the words, not the dictionary.
Here is how to get the items:
for(let index in arr) {
let item = arr[index];
// do something with the item
}
in your case something like:
for(let index in inputWords) {
let word = inputWords[index];
// do something with the word
}
For the lookup in the dictionary:
let value = dict[key]
In your case something like:
let translation = englishToFrench[word]
+ 2
I made explanations and fixes right in the code â see the comments in the JS tab.
I think you tried to get input text from the wrong element and your iteration of the dictionary didn't work.
https://code.sololearn.com/W6nRloZNHED8/?ref=app