@ejim11
Posted
if you are using js, you can make use of paddingStart(0,2). meaning 0 is the number in front if the digit is from 0-9.
Marked as helpful
@kaiohnr
Posted
@ejim11 Thanks!
I'd like to know what would be a better way to insert a zero in front of the number without have to repete those lines of code?
@ejim11
Posted
if you are using js, you can make use of paddingStart(0,2). meaning 0 is the number in front if the digit is from 0-9.
Marked as helpful
@kaiohnr
Posted
@ejim11 Thanks!
@ejim11
Posted
const timeLeftNow = { day: String(Math.trunc(totalSeconds / (60 * 60 * 24))).padStart(2, 0), hour: String(Math.trunc((totalSeconds / (60 * 60)) % 24)).padStart(2, 0), minute: String(Math.trunc((totalSeconds / 60) % 60)).padStart(2, 0), second: String(Math.trunc(totalSeconds % 60)).padStart(2, 0), };
Join thousands of Frontend Mentor community members taking the challenges, sharing resources, helping each other, and chatting about all things front-end!
Join our Discord