Transcript

Titles: Conditional Code.

Tim Kettering, Software Engineer at Lyft, sits in front of a gray background.
He wears a blue button down shirt with jeans.

Now, Tim signs.

Tim: You’ve learned how to use commands, you’ve created and made use of functions, and you’ve even incorporated loops! Now you’re at the point where you want your code to decide to perform a certain command. I’ll use the example of a function called goToBeach.

You don’t normally go to the beach every day. You’d only go on a weekend, and if it’s hot outside. Let’s go back to your coding. You want to decide whether to execute the goToBeach function. You would call two commands: isItHot and isItWeekend. If the outcome of both commands is true, then your code would decide to execute goToBeach.

There are many types of conditionals, but for this video, we will only cover two of them. The first type of conditional is “AND”. “AND” only happens if all conditions are true. Going back to the goToBeach example, the conditionals are isItHot and isItWeekend. Both must be satisfied in the “AND” conditional for the goToBeach function to run.

The second type of conditional is “OR”. The “OR” conditional executes if any of the conditions are true. Here’s an example: You come home, you just want to play video games. But someone tells you you can’t, until you either clean your room or wash the dishes, and then you can play video games. So, you’d roll your eyes and you’d clean your room and then play video games. Or you’d wash the dishes and then play.

So the difference between “AND” and “OR” is that with the “AND” conditional, all conditions must be true for the function to run. For the “OR” conditional, at least one or more of the conditions must be true for the function to run. That’s the difference between “AND” and “OR”. And that’s conditional code!

An Apple logo.

More Videos

Watch more videos of Will and Tim, software engineers at Lyft, as they explain coding concepts in American Sign Language and give advice on app development from a Deaf perspective. View all videos