如何解决翻译提醒问题
我在上一篇文章的评论者的帮助下创建了一个新版本的翻译器,但是现在我遇到了一个问题,即使用户输入了正确的数字并选择了语言“法语”带有大写字母,您将在 else 语句中获得翻译和错误消息。德语翻译不会发生这种情况,效果很好,只会发生在法语翻译中。为什么会发生这种情况?
//This is the code for the 'Amazing Translator' app. This code was written by Nathan Hart. For maintentance tips or to add features see attached comments.
//This is the array storing all French translations from 1-30. Note: The first value "Please enter a number between 1-30" is '0'.
var frenchTranslation = ["Please enter a number between 1-30","un","deux","trois","quatre","cinq","six","sept","huit","neuf","dix","onze","douze","treize","quatorze","quinze","seize","dix-sept","dix-huit","dix-neuf","vingt","vingt et un","vingt-deux","vingt-trois","vingt-quatre","vingt-cinq","vingt-six","vingt-sept","vingt huit","vingt-neuf","trente"];
//This is the array storing all German Translations from 1-30. Note: The first value "Please enter a number between 1-30" is '0'.
var germanTranslation = ["Please enter a number between 1-30","Eins","Zwei","Drei","Vier","Fünf","Sechs","Sieben","Acht","Neun","Zehn","Elf","Zwölf","Dreizehn","Vierzehn","Fünfzehn","Sechzehn","Siebzehn","Achtzehn","Neunzehn","Zwanzig","Einundzwanzig","Zweiundzwanzig","Dreiundzwanzig","Vierundzwanzig","Fünfundzwanzig","Sechsundzwanzig","Siebenundzwanzig","Achtundzwanzig","Neunundzwanzig","Dreiβig"];
/*This is the function used to translate the number chosen by the user into the translation
language chosen by the user. I have used 'const' instead of 'let' as 'let' is generally used for loops.
The if else statements are self explanatory,the only thing that may need changing in due time is
the values if the amount of numbers were to expand,and additional translations would be needed in the above arrays.*/
function translate()
{
const yournumber = Number(prompt("Enter your number (1-30)"));
console.log(yournumber);
const language = prompt("Choose a language - German or French");
console.log(language);
if(yournumber < 1 || yournumber > 30) {
//This is the error allert for if a user inputs a void number.
alert("There was an issue with your chosen number. Please enter a number between 1-30 and try again.");
}
else {
if(language === "French") {
//The alert for a successful French translation.
alert("Your French translation is: "+frenchTranslation[yournumber]);
}
if(language === "German") {
//The alert for a successful German translation.
alert("Your German translation is: "+germanTranslation[yournumber]);
}
/*This is the error message for an invalid language. NOTE: This is case senistive,so users need to capatalize 'French' or 'German'.*/
else {
alert("Please enter a valid language(German or French). These are case sensitive.");
}
}
}
//This is the call for the translate function. Without this the function will not run,so do not delete it.
translate();
//End of code.
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。