Northcentral Technical College Introduction To Programming
10-152-310
Introduction to Programming with JavaScript NTC 10-152-310

Learning Plan 4 If Statement With Multiple Boolean Expressions

# If Statement With Multiple Boolean Expressions

#### File: /Learning Plan 4/multipleBooleans.html

### Readings

- Head First JavaScript
  - Chapter

## This `OR` That, This `AND` That

> Sometimes we want to have multiple conditions because one isn't enough.

- "If I were taller `OR` that shelf was lower, I could reach that can of soup."
- "Could I have 20 ones `OR` a ten and 10 ones `OR` even 2 fives and 10 ones?
- "You have to wear a shirt `AND` shoes to enter this premise!"
- "If you are older than 5 `AND` younger than 12 then the cost is $1"

### The Logical `OR` (`||`)

- In JavaScript the logical `OR` is `||`. That's two vertical bars. That key is in different places depending on the keyboard. Where is it on yours? You use it like this:

- Either one of the expressions can be true and the whole thing is true!
- Notice that you have to repeat the variable after the `||`. This is wrong:
- This is correct:

### The Logical `AND` (`&&`)

- In JavaScript the logical `AND` is `&&`, two ampersands. Here's how we use it:

- Both of the boolean expression has to be true. If either one is false then the whole thing is false.

### Examples

- Here's a logical AND example

- Here's an `if/else`

### Full `Multiple Booleans` Example

- Here's an example with a small twist: Drivers License

### It's lab time

- I am not young enough to know everything. - Oscar Wilde

- 4.3 Lab 1
- 4.3 Assignment 1