Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

182
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda