This lesson is for PRO members.

Unlock this lesson NOW!
Already subscribed? sign in

Adding Conditional Logic with Filter

1:01 RxJS lesson by

Often you only want values to proceed through your stream if they meet certain criteria, just as if you were using an if statement in plain JavaScript. This lesson shows you how to use filter on your stream to only push the values that you need through your stream.

Get the Code Now
click to level up

egghead.io comment guidelines

Avatar
egghead.io

Often you only want values to proceed through your stream if they meet certain criteria, just as if you were using an if statement in plain JavaScript. This lesson shows you how to use filter on your stream to only push the values that you need through your stream.

The game will be to type in the input, the current time on the timer. If I type in zero, since the count is currently at zero, that would be a point. If I type in one, it wouldn't be a point because those aren't the same.

When I start the timer, I'd have to type in one, or two, or three. That wouldn't be a point. That's not a point. And so on.

The way that works is by adding a filter that can take that data object and then compare the data.count to the data.text. It will parseInt the text just to turn it into a number, then hit save.

You can see that zero will give us a point but one won't because it didn't log out anything. As soon as I start the timer, when I hit one, then type two, then type three. I missed it. Try six now, seven or eight. I got eight. 10.

I scored points for 10, 8, 6, 2, and 1.

HEY, QUICK QUESTION!
Joel's Head
Why are we asking?