I would like to make a multilingual tool in JavaScript. I need to match words with their pair in other language. I would like to use 3 different languages. User inputs names of vegetables, chooses one of several languages and gets the right output.
var VegetablesInput = ["tomato", "potato", "cucumber", "carrot"]
var Italian = ["pomodoro", "patata", "cetriolo", "carota"]
var Croatian = ["rajčica", "krumpir", "krastavac", "mrkva"]
var Spanish = ["tomate", "patata", "pepino", "zanahoria"]
var languageInput = prompt ("Choose Italian, Croatian or Spanish.");
var languageInput = languageInput.toLowerCase();
function MatchTheWord (language, word) if (languageInput=="italian" &&
WordInput
== "croatian" && WordInput == "spanish") {
}
I would like to match an element of the VegetablesInput array with the right word according to the language chosen. But I am not sure how to do it simply by looping through the arrays inside the function. Any help would be appreciated.
function functionName(params) { code }. Put{between)andif, and remove from after"Spanish"). Also, if youtoLowerCase(), then don't capitalize in theif` ("Italian", for example). = for starters.indexOfWord = VegetablesInput.indexOf(word), and if-1, then "Not found", else, returnlanguage[indexOfWord]. May I recommend putting the language arrays in an object with key as language?translatedWords={"italian":["pomodoro", "patata", "cetriolo", "carota"], "croatian":["rajčica", "krumpir", "krastavac", "mrkva"], "spanish":["tomate", "patata", "pepino", "zanahoria"]}- then, iflanguage=="italian"andword=="potato",translatedWords[language][VegetablesInput.indexOf(word)]will return "patata".