Adding Conditional Logic with Filter

John Lindquist
InstructorJohn Lindquist
Share this video with your friends

Social Share Links

Send Tweet
Published 8 years ago
Updated 5 years ago

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.

[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.

egghead
egghead
~ 11 minutes ago

Member comments are a way for members to communicate, interact, and ask questions about a lesson.

The instructor or someone from the community might respond to your question Here are a few basic guidelines to commenting on egghead.io

Be on-Topic

Comments are for discussing a lesson. If you're having a general issue with the website functionality, please contact us at support@egghead.io.

Avoid meta-discussion

  • This was great!
  • This was horrible!
  • I didn't like this because it didn't match my skill level.
  • +1 It will likely be deleted as spam.

Code Problems?

Should be accompanied by code! Codesandbox or Stackblitz provide a way to share code and discuss it in context

Details and Context

Vague question? Vague answer. Any details and context you can provide will lure more interesting answers!

Markdown supported.
Become a member to join the discussionEnroll Today