This Lesson is for Members

Subscribe today and get access to all lessons! Plus direct HD download for offline use, enhances transcripts, member comment forums, and iTunes "podcast" RSS feed. Level up your skills now!

Unlock This Lesson

Already subscribed? Sign In

Autoplay

    Adding Conditional Logic with Filter

    John LindquistJohn Lindquist

    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.

    rxjsRxJS
    ^5.0.0
    Code

    Code

    Become a Member to view code

    You must be a Member to view code

    Access all courses and lessons, track your progress, gain confidence and expertise.

    Become a Member
    and unlock code for this lesson
    Transcript

    Transcript

    00:00 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.

    00:12 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.

    00:22 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.

    00:40 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.

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

    Discuss

    Discuss