Beginner's query about functions in JavaScript

Hello, I am currently tackling a programming challenge that requires the use of both a function and an array. As a novice programmer, I need a program that prompts the user to enter a number between 1 and 30, which should then be translated into either French or German. While I’ve managed to complete the task without functions, I realize I need to incorporate a function into my code. My grasp of functions is quite basic, and though I’ve watched many tutorials, I’m still missing something important. I will share my current implementation with comments to illustrate my thought process. I appreciate any assistance you can provide!

function convertNumberToLanguage(num, language) {
    let result = language === "french" ? frenchNumbers[num] : germanNumbers[num];
    return result;
}

let frenchNumbers = ["zéro", "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"];

let germanNumbers = ["null", "eins", "zwei", "drei", "vier", "fünf", "sechs", "sieben", "acht", "neun", "zehn", "elf", "zwölf", "dreizehn", "vierzehn", "fünfzehn", "sechszehn", "siebzehn", "achtzehn", "neunzehn", "zwanzig", "einundzwanzig", "zweiundzwanzig", "dreiundzwanzig", "vierundzwanzig", "fünfundzwanzig", "sechsundzwanzig", "siebenundzwanzig", "achtundzwanzig", "neunundzwanzig", "dreißig"];

let inputNumber = prompt("Please enter a number for translation:");
while (inputNumber < 1 || inputNumber > 30) {
    alert("The number must be between 1 and 30.");
    inputNumber = prompt("Please enter a number for translation:");
}

let inputLanguage = prompt("Which language would you like: French or German?");
while (inputLanguage.toLowerCase() !== "french" && inputLanguage.toLowerCase() !== "german") {
    alert("Please respond with either 'French' or 'German'.");
    inputLanguage = prompt("Which language would you like: French or German?");
}

let resultTranslation = convertNumberToLanguage(inputNumber, inputLanguage);
alert(inputNumber + " translates to " + resultTranslation + " in " + inputLanguage);