Interactive online courses HTML Academy
2026-03-09 14:11 Diff

We learned how to obtain the filter value when the user switches the category. In order for the filtering to work, we need to compare the selected value with the category of each news story on the page.

We have already written a loop that goes through all the news stories and compares the category of each of them with a string. Move this loop inside the onchange event handler and change the arbitrary string to the filter value.

// Before for (let article of articles) { if (article.dataset.category === 'cats') { … } } // After filter.onchange = function () { for (let article of articles) { if (article.dataset.category === filter.value) { … } } };

Let’s check that everything works: change the filter value and make sure that the news stories from the selected category are highlighted.