lundi 5 avril 2021

How to implement days and hours logic using if else operator?

I wanted to implement days and hours logic in my code using ternary functions.

{hours.length > 0  


? days.length > 0 ?<div>{days} days and {hours} hours</div> 
: <div>{hours} hours</div>

: <div>{days} days</div>}

I want to add checks so that it would display appropriate values. How can I do so? For instance, if days = 1, it would display 1 day instead of 2 and if there are both days and hours, it would put and accordingly. How can I do that?

Aucun commentaire:

Enregistrer un commentaire