Submitted about 4 years agoA solution to the GitHub user search app challenge
GitHub User Search App — Mobile-1st, SASS, BEM, API & JS.
accessibility, bem, sass/scss, fetch
LVL 1
@DanyGlez94

Solution retrospective
Hi everyone! Thanks in advance for checking out my code! Any suggestions are welcomed! 😜
If you want to know how to find out if the user prefers dark or light mode based on their device preferences, check out my code, it took me a while to find out how to do it, but it was easier than I thought.
const darkOrLight = () => {
const dark = window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches;
if (dark === true) {
console.log('User prefers dark mode');
} else {
console.log('User prefers light mode');
document.body.classList.add('light');
}
}
Happy coding! 😉✌
Code
Loading...
Please log in to post a comment
Log in with GitHubCommunity feedback
No feedback yet. Be the first to give feedback on Daniel González’s solution.
Join 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