Very new to learning Javascript and have super limited knowledge and am a bit lost. I'm creating a console based program that will basically translate a number into a different language. The number needs to be between 1 and 30, and can only be translated into French or German. I have added all of the French/German translations into two separate arrays, however I need to use a function to get my result (currently using 'if' statements, which is working fine but not what I need to do). I haven't added a function yet and this is my code (incomplete but hopefully you get the idea)
console.log("Start of the program");
var number= prompt ("Which number between 1 and 30 do you want to translate?");
if (number <1) {
alert("Please enter a number between 1 and 30");
var number= prompt ("Which number between 1 and 30 do you want to translate?");
if (number >30) {
alert("Please enter a number between 1 and 30");
var number= prompt ("Which number between 1 and 30 do you want to translate?");
}
}
if (number => 1 && number <= 30) {
var lang= prompt ("Which language do you want to translate into, French or German?");
}
var frenchNumbers = ["Zéro", "Un", "Deux", "Trois", "Quatre", "Cinq", "Six", "Sept", "Huit", "Neuf", "Dix", "Onze", "Douze", "Treize", "Quatorze",
"Quinze", "Sieze", "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"];
var germanNumbers = ["Null", "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"];
if (number == 1 && lang == "French") {
alert(frenchNumbers[1]);
}
This works perfectly fine, but I need it to do the same thing but using a function, and I just can't get my head around it. I need to follow this template:
function translate(number,lang){
//your code here;
return translatedNumber;
}
Any help would be greatly appreciated, Thanks, Brad