Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialSeth Missiaen
Web Development Techdegree Graduate 21,652 PointsIs there any issue with using for of loops instead of the basic for loop?
I solved the filter checkbox problem like this:
filterCheckBox.addEventListener('change', (e) => {
const isChecked = e.target.checked;
const lis = ul.children;
if (isChecked) {
for (each of lis)
if (each.className === 'responded') {
each.style.display = '';
} else {
each.style.display = 'none';
}
} else {
for (each of lis) {
each.style.display = '';
}
}
});
I felt that for of loops were neater and quicker to write. Is there any problems with this approach?
Thanks!
1 Answer
Steven Parker
231,269 PointsAs you discovered, it's an effective and concise approach, so you're likely just getting ahead of things. Unless for ... of
was introduced earlier in this same course, it was probably not used to avoid any confusion.
Seth Missiaen
Web Development Techdegree Graduate 21,652 PointsSeth Missiaen
Web Development Techdegree Graduate 21,652 PointsThanks Steven! Insightful response as always!