Design comparison
SolutionDesign
Solution retrospective
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?
Community feedback
- @ejim11Posted over 2 years ago
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 helpful1 - @ejim11Posted over 2 years ago
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), };
0
Please log in to post a comment
Log in with GitHubJoin our Discord community
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