JavaScript 3 - Conditionals, Comparisons, Booleans

Projected Time

About 2.5 hours

Prerequisites

Motivation

JavaScript is used on the frontend of almost every website. It’s also a widely-used scripting language that be used on the backend as well. The JavaScript lessons set a solid foundation in JavaScript basics so we can use the language in more robust ways in later lessons.

Objectives

Participants will be able to:

Specific Things to Learn

Lesson

Things to Remember

Demonstration

Instructor demonstrates in the video walkthrough how to work with comparison operators, Booleans, if/else and logical operators in JavaScript.

Independent Practice

Techtonica staff will assign pairs.

Activity: Movie Night Suppose 5 classmates are interested in going to see a movie together. There are some interesting dynamics between the people in this group, as described below:

Write a function called movieNight that takes in an array. The array must contain 3 strings, and each string must be one of the names shown above who are interested in going to the movies. And the array should include all the combinaton of three names out of five(total 10 possible array input). Write a body for the movieNight function, based on the “rules” associated with each of the names above, that returns an array of the people who will attend the movie. Your function should account for the logic necessary for all 5 people, so that no matter which names are given, the result will always be correct. (ie: Don’t just code the logic for 3 of the names and pass those names in all the time.) In case there are multiple answer for a single triplet or input string display all the possible correct answer for that triplet.

Result for different combination of input array

Example For example, movieNight(['Priya', 'David', 'Breanna']) should return ['David', 'Alex', 'Breanna'] because:

  1. Alex gets added automatically because David is going
  2. Priya doesn’t go because Ming is not going.
  3. Breanna will go because there are at least 2 others going

Things to Consider

Group Practice

Techtonica staff will assign new pairs. With your new pair, share your code with one another. It’s OK if you didn’t finish! Your new pair might be able to give you some suggestions, or you might get some ideas from their code. Discuss what you found challenging about this activity.

Challenge

Supplemental Resources

JavaScript Comparison Operators

JavaScript Boolean Values

JavaScript Conditional Statements

JavaScript Logical Operators

General JavaScript

Check for Understanding