Skip to content

Commit

Permalink
Merge pull request #56 from turingschool/28-async-boolean-logic
Browse files Browse the repository at this point in the history
Add JS examples, add async lesson to index
  • Loading branch information
jamisonordway authored May 21, 2024
2 parents 455456e + ff9296e commit 63f319e
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 10 deletions.
53 changes: 44 additions & 9 deletions module1/lessons/boolean_logic.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ tags: ruby, computer science, logic

## Learning Goals

* explain falsy vs truthy in Ruby
* explain "falsy" vs "truthy"
* apply the key logic operators AND, OR, and NOT
* combine operations into a logic expression
* utilize a truth table to illustrate a logical expression
Expand All @@ -22,16 +22,17 @@ tags: ruby, computer science, logic
* Truth Table
* Flow Control

## Slides

Available [here](../slides/boolean_logic)

## WarmUp

First, start by doing some research.
You may choose independent or paired.

#### Truthy and falsey values
#### Truthy and falsy

* What do you think it means to describe something as 'truthy'?
* What about 'falsy'?

#### Truthy and falsy values in Ruby

* How many falsey values are there in Ruby?
* What is truthy in Ruby?
Expand All @@ -54,6 +55,14 @@ Values to Check:
* true
* "false"

<section class="dropdown">

### What about Truthy and Falsy in JS?
In JavaScript, all values are truthy except
`false`, `0`, `-0`, `null`, `undefined`, `NaN`, and `document.all`.

</section>

## Why?

Why is it helpful to have a working understanding of boolean logic? It can help us flatten `if` statements and reduce the number of lines in our code. We are also going to encounter this frequently in our jobs. A lack in understanding can introduce bugs into our code bases.
Expand Down Expand Up @@ -140,6 +149,32 @@ Let's revisit that last expressions in `pry`, but let's add some parentheses.
false && false || true
false && (false || true)
```

<section class="dropdown">

### Expressions in JavaScript

These expressions will also work in JavaScript:

```javascript
function determineTruthyness(expression) {
if (expression) {
return `The expression ${expression} is true!`
} else {
return `The expression ${expression} is false!`
}
}

var exp_1 = false && false || true
var exp_2 = false && (false || true)

determineTruthyness(exp_1);
determineTruthyness(exp_2);
```

</section>


**Turn & Talk**
Turn to your neighbor and discuss what order you believe Ruby is evaluating each boolean expression in. What will the result be?

Expand Down Expand Up @@ -263,6 +298,6 @@ Convert the nested if/else statements to flatter boolean expressions.

## Wrapup

* What objects are truthy? What objects are falsey?
* What are the rules of precedence in Boolean expressions?
* Why might you use complex Boolean expressions?
* What objects are truthy in Ruby? What objects are falsey?
* What are the rules of precedence for Boolean expressions in Ruby?
* Why might you use complex Boolean expressions?
2 changes: 1 addition & 1 deletion module1/lessons/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ title: Module 1 - Lessons
<!-- * [Flow Control](./flow_control) -->
<!-- * [Beginner Enumerables](./beginner_enumerables) -->
<!-- * [Hashes](./hashes) -->
<!-- * [Boolean Logic](./boolean_logic) -->
* [Boolean Logic](./boolean_logic)
<!-- * [Nested Collections](./nested_collections) -->
<!-- * [Reaching Through Objects](!needs lesson plan!) -->
<!-- * [Intermediate Enumerables](./intermediate_enumerables) -->
Expand Down

0 comments on commit 63f319e

Please sign in to comment.