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

306
Visualizações
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 à 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