0

Why this JavaScript doesn't translate words from input, please help me.

https://code.sololearn.com/W68mZGwSxs5Z/?ref=app

19th Dec 2021, 11:03 AM
Gaoussou Maiga
Gaoussou Maiga - avatar
2 Antworten
+ 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]
19th Dec 2021, 11:40 AM
Alex
Alex - avatar
+ 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
19th Dec 2021, 11:40 AM
Lisa
Lisa - avatar