[英]How to return the value of the second array through the input of the first array
I would like to make a multilingual tool in JavaScript.我想在 JavaScript 中制作一个多语言工具。 I need to match words with their pair in other language.我需要将单词与其他语言中的单词配对。 I would like to use 3 different languages.我想使用 3 种不同的语言。 User inputs names of vegetables, chooses one of several languages and gets the right output.用户输入蔬菜名称,选择几种语言中的一种并获得正确的 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.但我不知道如何简单地通过循环通过 function 内的 arrays 来做到这一点。 Any help would be appreciated.任何帮助,将不胜感激。
Hope this help:希望这有帮助:
var Vegetables = {
it: {
tomato: "pomodoro",
potato: "patata",
cucumber: "cetriolo",
carrot: "carota",
},
cr: {
tomato: "rajčica",
potato: "krumpir",
cucumber: "krastavac",
carrot: "mrkva",
},
sp: {
tomato: "tomate",
potato: "patata",
cucumber: "pepino",
carrot: "zanahoria",
},
};
var languageInput = prompt("Choose Italian, Croatian or Spanish.");
var languageInput = languageInput.toLowerCase();
var wordInput = prompt("Choose Word: tomato, potato, cucumber, carrot.");
var translatedWord = Vegetables[languageInput][wordInput]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.