Design comparison
Solution retrospective
I also added an additional feature, dark and light mode. Please i need a feedback on the view especially. And also i noticed that the time doesn't countdown on some phones. please your feedbacks will really help me thanks.
Community feedback
- @mickygingerPosted about 3 years ago
Hi Eugene! 👋
Firstly this looks great, and I love that you've added your own spin to the design with the Christmas theme.
The
setInterval
in your code is probably not behaving quite as you expect. The second argument is the delay between executions of the callback in milliseconds. So for example:setTimeout(() => { console.log('Hi Eugene'); }, 5000)
Would print
Hi Eugene
to the console every 5000ms (or 5s) for ever (and ever and ever...).You've set the delay to
Infinity
which by some strange twist of JavaScript logic is converted into 0, which means you're executing the callback as soon as possible at the time, but realistically probably 100s or 1000s of times a second.Since you only need the clock to tick every second, you can change
Infinity
to something a little less demanding like1000
or perhaps500
if you want the clock to tick closer to the actual time your system clock ticks. Anything lower than60
is redundant because that's likely to be your screen refresh rate, so you wouldn't notice it at all.You can stop the
setInterval
withclearInterval
. This StackOverflow post has some good examples.You should also grab your clock's DOM elements outside of the callback, because otherwise you're retrieving them from the page every time the callback runs (which is an expensive operation for JavaScript). Something like this will be a lot more efficient:
const days = document.querySelector('#days'); const hours = document.querySelector('#hours'); const minutes = document.querySelector('#minutes'); const seconds = document.querySelector('#seconds'); setInterval(e => { // rest of code }, 1000);
OK, I hope that all makes sense. Please let me know if you have any questions!
1
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