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

115
Vistas
Ternary Operator

I recently started learning Ternary Operator. However I am stuck in this specific one. In JavaScript language, I want to check if a student is a member of the library, if the student is, it has to print "You are a member!" if not, it has to print "Not found!". To check, we can use the student id for the validation of the library membership.

about 4 years ago · Santiago Gelvez
1 Respuestas
Responde la pregunta

0

It would be easier for me to tailor my answer to your need if I had some code to work with. But basically, you can use something as simple as:

studentIsMember ? 'You are a member' : 'Not found!'

This will print 'You are a member' if studentIsMember is true and 'Not Found' if false.

If you need to lookup students in a members list using their id, you can have something like:

members.includes(student.id) ? 'You are a member' : 'Not found!'

this will look into the members array which holds an array of all members IDs and see if the specific student id is in that array.

Lastly, if you have to do more operations to validate a student's membership status, you can write a function that does the operations and returns true or false depending on whether the student is a member or not, and then use the ternary operator like this:

studentIsMember(student.id) ? 'You are a member' : 'Not found!'

Hope this helps.

about 4 years ago · Santiago Gelvez 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