Matias Ludueña• 1,990
@matiasluduena23
Posted
Hi SUBHI-05’S! Congratulations you finished the challenge! Just one recommendation that might help you.
- try to write all you Javascript code in your JS file, is more clean and easy to debbug. Maybe you can get all your
rating-item
and look for a click to apply the class active and remove for the other ranting elements. Something like this:
const allRatingItem = document.querySelectorAll('.rating-item');
allRatingItem.forEach((item) => {
item.addEventListener('click', (e) => {
removeClass();
item.classList.add("rating-item-clicked")
})
})
function removeClass(){
allRatingItem.forEach((item) => {
item.classList.remove("rating-item-clicked")
})
}
- A good practice is to be more modular, a function only has to do one thing. Hope this help you!
Good code!
Matias
Marked as helpful
1
Subhi-05• 30
@Subhi-05
Posted
@matiasluduena23 Thank You so much!! It helped me and I'll definitely try adding this dynamic functions.
0