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

181
Visualizações
which is the proper syntax for javascript?
var age = prompt("Enter your age");
  if (age < 18){
   alert("Sorry, you are too yound to drive this car. Powering off");
   }
  else if (age > 18){
   alert("Powering On. Enjoy the ride!");
   }
  else if(age == 18){
   alert("Congratulations on your first year of driving. Enjoy the ride!");
   }

or

var age = prompt("What is your age?");

  if (Number(age) < 18) {
    alert("Sorry, you are too yound to drive this car. Powering off");
  } 
  else if (Number(age) > 18) {
    alert("Powering On. Enjoy the ride!");
  } 
  else if (Number(age) === 18) {
    alert("Congratulations on your first year of driving. Enjoy the ride!");
  }

which of the syntax is better? and why?...relating to the Boolean condition of the if/else...if statement

about 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

That is not a question of syntax, the code you provided is good in any cases. However, if you want an accurate result and a clean code, you should transform your prompted result into a number. Keep in mind that Javascript in a dynamic typed language, so if the number as a string is compared to a number, they both will be compared as string.

about 4 years ago · Santiago Trujillo Relatório
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