Interactive online courses HTML Academy
2026-03-09 10:48 Diff

Great job! Now highlighting has been added to the news stories from the category that has been selected in the filter. When a user selects a category from the list, only news stories from the selected category should be displayed on the page, and the remaining news stories from all other categories should disappear.

In order to make the news story disappear from the page, you need to add the hidden class to it. Now we are adding a class that is responsible for adding a highlight to those news stories whose categories match the filter value. But how can we do the opposite, namely add a class to news stories whose categories differ? To do this, we use the strict inequality operator. It is indicated by an exclamation mark and two equal signs:

'a' !== 'a'; // Result: false 'a' !== 'b'; // Result: true

The strict inequality operator performs the exact opposite function of the strict equality operator. If the values are equal, it will return false, and if they are not equal, then it will return true.

Let’s continue to deploy filtering on our news site. Change the condition in the if statement so that the color highlighting is added to news stories from all categories except for the selected one. Then change the highlight class that is responsible for highlighting to the hidden class. This class will hide all of the extra news stories. After that, check that the news items from the unselected categories are in fact hidden.

JavaScript also has a non-strict inequality operator: !=. We will talk about how it differs from the strict inequality operator in one of the following chapters.