Exercise Wednesday

Goal: In the More Branching lesson, we learned about:

  • The logical "and" && and the logical "or" || operators
  • The logical "not" ! operator
  • The JavaScript values of truthy and falsey

Practice using these operators, and begin familiarizing yourself with the concepts of truthy and falsey by completing the exercises listed below.

Warm Up


  • What is an example of something JavaScript considers to be falsey? Why is it falsey?
  • What condition does the following line of code check for? In the example, blue, red, and purple are variables.
if (blue === true && red === false || purple === true)

Code


Meet the goal by completing one of the practice prompts below.

Both sites should check for any form fields the user has left blank. If you're checking multiple fields, don't pop up a dialog box for each one; that could get annoying if the user has left multiple fields blank! Instead, insert text next to the field the user has missed. Bootstrap has some nice styles for this — check out the Validation section of their form documentation.

Celebrity Dating Quiz

Create a celebrity dating webpage, where you enter information about yourself, and the page suggests which celebrity, fictional character, or public figure you would be most compatible with.

How you decide to calculate the compatibility can be arbitrary. Just make sure to try out using the || and && operators.

Political Meter

Make a political belief meter/quiz that asks questions about users' values, and determines how liberal, moderate, or conservative they are.

How you decide to calculate how liberal, moderate, or conservative a user is can be arbitrary. Just make sure to try out using the || and && operators.

Lesson 59 of 72
Last updated July 15, 2022