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

113
Visualizações
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 Respostas
Responde à pergunta

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 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