# Logic

Slides Here!

## In Class Exercises (ICEs)

### Part 1: Creating logical expressions from English verbiage

Go through and for each question try to come up with a logical expression that says when the written text is true

Example:

Given the following English text:
The toast is done when the toaster goes 'ding' or when the toast itself is nicely browned and not smoking

You might write out the following logical expression:
The toast is done when:
(the toaster goes 'ding')
OR ( (the toast is nicely browned) AND  NOT (the toast is smoking)  )

Exercises:
1. Given:
I'll be finished with my homework when I've done problems #1, #2, and #3
Write out a logical expression that completes the following:
I'll be finished with my homework when:
2. Given:
I'm going to flee the building if the building floods, lightning strikes the building, or the building starts to collapse
Write out a logical expression that completes the following:
I'm going to flee the building if:
3. Given:
My child is ready to leave the house in the morning when they've made their bed, used the restroom, eaten all his/her breakfast, and is not stalling.
Write out a logical expression that completes the following:
My child is ready to leave the house in the morning when:
4. Given:
We're going to leave when the game is over.  Unless we sit here for more than 10 minutes, in which case we'll leave then.
Write out a logical expression that completes the following:
We're going to leave when:

(You could 'translate' the previous ones mostly by re-arranging the phrases in the sentences and putting in AND/OR/NOT.  For this one you'll need to re-write things a bit more)
5. Given:
Take the bread out of the oven when the inside of the loaf hits 208 degrees; don't leave the bread in for more than 40 minutes.
Write out a logical expression that completes the following:
Take the bread out of the oven when:
6. Given:
Imagine that you're driving on an interstate highway.  Before we pull over and take a break we're going to drive for an hour.  After that, we'll stop at the first exit that has gas or has a restroom.
Write out a logical expression that completes the following:
We're going to stop when:
7. Given:
Your dinner is complete if you have a Caesar Salad or a house salad, along with a slice of pizza or a chunk of lasagna.
Write out a logical expression that completes the following:

### Part 2: Modifying the provided example file

Save yourself your own copy of the 'Logical Operators and and JavaScript demonstration files, so that you can modify them for this excise.

Once you've done that, make the following changes to the file.  Make sure to stop and review your changes so that you can really get the ideas and the code into your head solidly.

1. First, change the ranges that the page is checking for.  For example, instead of saying that anything in the range of 20-40 is 'close', you could change the page so that it says that anything in the range 15-37 is 'close'.
Make sure that you change the overall of acceptable numbers from 1-100 to being -100 to +200.
2. Add a second number to check for.  When you're done 30 is still a correct answer, but 170 will also be a correct answer.
3. Change that page so that in addition to saying 20-40 is 'close' (or 15-37, or whatever range you've got), the page will also say that 150-180 is 'close'.
Do this using a separate, stand-alone else if for now.
4. Comment out the else if from the prior step, then combine that second range (from step 3) in with the original 'it's close' check.  When you're done you'll have a single else if checking for both ranges

### Part 3: Logical ops w/ radio buttons and check boxes

Do the following: