0
[solved] ⊠is not a function
I wrote onchange="translate()" for an input text. The function translate() is available and spelled correctly, but it shows "translate is not a function" if you submit the text. Why?? https://code.sololearn.com/WLwJT8w5t1zG/?ref=app I also tried to leave the app, clear cacheâŠ
8 Answers
+ 3
I can't seem to reproduce any such error, it works just fine here, except for the translate function is only setting a variable value for now, not yet translating the input.
+ 2
Well good for you đ, but honestly, before, even when the function name was `translate` I could get it to run anyways, no errors.
+ 2
May I ask how you will do the language translation?
+ 2
I will declare two arrays (one for German, one for English).
It will look like this:
var german = ["hallo", "Fenster", "Hut"];
var english = ["hello", "window", "hat"];
german[i] means english[i].
The input will be splittet by spaces and the code will check if the word contains a known word.
Example:
input (german) = "Ich fahre mit der Eisenbahn."
input = input.split(" ");
//for-loop
actual_word = "Eisenbahn";
//Suppose that "Eisen" (iron) and "Bahn" (train) are known in the array (but not "Eisenbahn").
//The code will replace "Eisen" with "iron" and "bahn" with "train". ("iron" has the same array index in english as "Eisen" in german.)
The output should be "I drive with the irontrain." (instead of "I'm going by train."). That should be funny.
It should go from big to small:
If the word is "mein" ("mein"="my", "ein"="a", "in"="in") and all these three words (mein, ein, in) are known, it shouldn't translate "ma" or "mein" (because it sees ein or in, translates that first)
+ 2
Nice idea! yeah word per word translation is different with regular translation. Well best of luck my friend! hope to see your code finish soon đ
+ 1
Every time I write something into the input field and press the enter (send) button it shows this error.
+ 1
I solved it by renaming the function. translate seems to be a keyword.
0
//Sorry, it was to long.
So I'll have to sort the words by their length. Then it should translate "my".
I will also write all the words in lower case and use .toLowerCase() so that it doesn't matter if the word is at the beginning of the sentence.