Interactive online courses HTML Academy
2026-03-09 12:24 Diff

We found all of the news stories on the page and added highlighting to them. This will help us to debug the code and configure filtering. We will filter news stories by category. The category of each news story is specified in its data attribute:

<article class="news-block" data-category="games"> … </article>

There are four possible values for the data-category: 'games', 'IT', 'HR', and 'cats'. The filter has the same values. When the user selects the category, we must compare the attribute value assigned to the news story with the selected value of the filter.

We already know how to compare two numbers and find out which one is larger. But how do you know that two values are equal to each other? We use the strict equality operator. It is indicated by three equal signs:

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

The strict equality operator compares two values and returns true if they are equal and false if they are not equal. The values that the operator checks for are called operands.

We will use the strict equality operator to create filtering for the news site. Add a conditional statement inside the loop and compare the value of the data-category attribute for each news item with one of the possible filter values. As a result, highlighting will be added to news stories from only one category.

JavaScript also has a non-strict equality operator: ==. We will talk about it in one of the following chapters.