Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

138
Visualizações
prompting the user to try again when input is invalid

Below is a java script code I wrote for an assignment - as a continuation of the assignment we have a task to test the code and fix/report any bugs or errors.

the code is to translate numbers 1-30 into French or German. my bug is that when the error pops up regarding an invalid language input it closes the program instead of prompting the user to input a valid language.

any ideas ? I've tried to use a prompt code but I may have added it incorrectly as it wasn't working for me.

var frenchTranslation = ["zero", "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"];



var germanTranslation = ["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"];


function translate()
{
const chosennumber = Number(prompt("Choose a number between 1-30"));


console.log(chosennumber); 

if(chosennumber < 1 || chosennumber > 30) {


 alert("Error!! Please enter a number between 1-30.");
translate();
}

const language = prompt("Choose a language – French or German");
console.log(language); 
{


if (language === "French") {


    alert("The French translation is: "+frenchTranslation[chosennumber]);
}
else if (language === "German") {


    alert("The German translation is: "+germanTranslation[chosennumber]);
}

 else {
             alert("ERROR! Please enter a valid language (German or French).");
} 
}
}
translate();
about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda