Design comparison
SolutionDesign
Solution retrospective
Hey there,
It's been a while since I worked with JS, so I'd love to receive feedback on this challenge :)
Community feedback
- @fazzaamiarsoPosted over 2 years ago
Hello @dalnoki! Nice work overall!
I did a quick refactor on your code.
const button = document.querySelector('.card__button'); const rating = document.getElementsByClassName('card__ratings'); const front = document.querySelector('.card__front'); const backText = document.querySelector('.card__text--selected'); let selectedNumber = 0; for (let i = 0; i < rating.length; i++) { rating[i].addEventListener("click", () => { selectedNumber = rating[i].value; }) } button.addEventListener("click", () => { backText.innerHTML = `You selected ${selectedNumber} out of 5` front.style.opacity = "0"; });
- you don't need to wrap the all of them IIFE. All of the listeners will still be attached.
- you can use
querySelector
to get a single element.
I hope it helps! Cheers!
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