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

307
Vistas
Using more than one conditions on placeholder (JS)

I'm starting to learn JS and one of my tasks is to create a simple code to give the system time. I also wanted to increment it so it would give hour or hours based on what value the variable had (if it was 1, then the text is "hour"... if it was 2, it would be changed to "hours"... and so on)

With the help of someone from this site, I made the following:

const d = new Date()
const [h,m,s] = [d.getHours(), d.getMinutes(), d.getSeconds()]
divid.innerHTML = `Agora são ${h} hora${(h!=1)?"s":""}, ${m} minuto${(m!=1)?"s":""} e ${s} 
segundo${(s!=1)?"s":""}!`

My question is: is there a way to put another condition on the placeholder like it was used here? Like... ${(h!=1, h!=0)?"s":""} ? So I would get the "s" (plural) on the text if the variable is NOT 0 or 1?

I've tried with || and also using double parentheses [ like ${(h!=1)(h!=0)?"... etc ]. But it didn't work. Is there a way to do this? Or I have to use something like switch or .split() ?

Thank you!

about 4 years ago · Juan Pablo Isaza
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