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!