## FUNctions!

Goal: Solidify students' understanding of functions: Input/Independent Variable/Domain → Output/Dependent Variable/Range

**Day 1 - CS Unplugged!**

**What is a function in CS?**

**Function 1:**WALKFORWARD

Input: (Steps)

The value written on the card inside of your envelope represents the value of (Steps) you should use.

Steps:

- Walk forward (Steps) number of steps (take baby steps).
- Sit down now that you are finished.

**Function 2:**MAKESQUARE

Input: (Steps)

The value written on the card inside of your envelope represents the value of (Steps) you should use.

Steps:

- Press the chalk against the ground directly where you are standing.
- Repeat the following steps 4 times:
- Move forward (Steps) number of centimeters.
- Turn 90 degrees.

- Move forward (Steps) number of centimeters.
- Pick the chalk up off the ground and sit down now that you are finished.

Debriefing:

- Why did everyone end up in different places and doing different things even though everyone is defined exactly the same?
- What decides how people carry out their steps?
- What would happen if instead of step 1 saying “Walk forward (Steps) number of steps,” it said “Walk forward 5 number of steps?” Would the function work the way it’s supposed to? Have you done this before on your homework?
- A generic function is one that can work with any input, adjusting its functionality accordingly. Is a function that ignores its input generic?

Code to Class:

Code to Class:

- If we wanted to code a robot to get back to the classroom what commands would we need?
- Using the commands we defined, small groups will work to come up with code to get a “robot” back to the classroom.
- One group will start giving the “robot” commands to follow. When they have an error, another group will start.
- Are there steps that repeat that could be put in a loop?

**Day 2: Pseudocode**

- How is code like a recipe? Create lemonade recipe as psuedocode.
- Has ingredients (variables)
- Runs top to bottom (in sequence)
- Conditions help you make decisions about what to do next
- Repeating steps can be put in a loop
- Write pseudocode for the following scenarios:
- You decide to raise some money for your favorite charity by selling lemonade. One hot weekend, you set up a lemonade stand in your neighborhood and charge $1.25 for a cup of lemonade.
- Your lemonade stand was a huge success so you decide to spend next summer selling lemonade and donating all of the profits to your favorite charity. You decide to continue to charge $1.25 for each cup but you want to be reimbursed for all of the money that you spend on supplies. You decide to buy a week’s worth of supplies at a time. The first week of supplies cost $45.00.
- The next summer you decide to expand your philanthropic enterprise. You decide to sell lemonade at $1.25 a cup and ice cream cones for $2.50.
- You and some friends decide to go tubing down the James River. The company charges $15 to rent a tube for a person and $7.50 to rent a tube for a cooler for food and drinks. Your group spends $360 an you rent 26 tubes. How many of each tube did you rent?
- You are conducting a chemistry experiment and you need 100 milliliters of a 3% hydrochloric acid solution. You have a large bottle of 1% hydrochloric acid and a large bottle of 5% hydrochloric acid. How many milliliters of each solution do you need to mix together?

**Day 3: Functions in JavaScript**

- Open this Thimble project: https://thimbleprojects.org/techkim/349755
- Run code. What does it do?
- How much money do you raise by selling 4 cups of lemonade?
- How much money do you raise by selling 50 cups of lemonade?

- Supplies cost $45/week.
- Remix this Thimble project.
- Add a new variable called supplies.
- Update the calculate function to show only profit.
- How many cups of lemonade must you sell to break even? (In other words, how many cups of lemonade must you sell to offset the cost of supplies?)
- What will your profit be if you sell 50 cups of lemonade?
- The $45.00 in supplies allows you to make 135 cups of lemonade. What is your maximum profit this week?
- How many cups do you have to sell per week to break even?

- Update code, so that it prompts user to input price.
- How many cups do you need to sell to break even at $0.75/cup?
- What price do you need to charge to earn a profit of at least $25 on 50 cups?

- Update the background image in style.css. Remember to give proper credit.
- Update the google fonts in style.css.