# Building Blocks of Code

_Learn the building blocks of coding through fun stories and play_

---

## Day 1: Sequences (Steps in Order)

A **sequence** is a set of instructions followed in order, one after another. Computers do exactly what you tell them, in exactly the order you say it. If you skip a step or mix up the order, things go wrong!

### Let's Try It

> "When we tell a computer what to do, we have to give it steps in order—just like a recipe! If we mix up the steps, things get silly."

Let's say we want to get Sparkle the horse ready for a ride. What do we do first?

```
Step 1: Find Sparkle in the field
Step 2: Put on the saddle
Step 3: Put on the bridle
Step 4: Climb on
Step 5: Say "Let's go!"
```

What if we tried to climb on Sparkle BEFORE we put the saddle on? That would be uncomfortable! Computers are the same way—they need the steps in the right order.

### Drawing Idea

Draw 4-5 boxes in a row (like a comic strip). Draw or describe what happens in each box to "get the horse ready." Number the boxes together.

---

## Day 2: Conditionals (If / Then)

A **conditional** is how computers make decisions. It's an "if this, then that" rule. The computer checks if something is true, and if it is, it does something.

### Let's Try It

> "Computers can make choices! They use a special rule called 'if-then.' Let's try it with rainbows!"

When do we see a rainbow?

```
IF it rained AND the sun comes out
THEN a rainbow appears!
```

Try another one with horses:

```
IF Sparkle is hungry
THEN give Sparkle an apple
```

And one with math:

```
IF 2 + 2 equals 4
THEN you got it right!
```

### Make It Silly

Make up your own if-then rules and act them out!

- IF I clap my hands, THEN you neigh like a horse!
- IF I say "rainbow," THEN you jump!

### Drawing Idea

Draw a simple flowchart: a cloud with rain on one side, an arrow pointing to a rainbow. Label it "IF rain + sun --> THEN rainbow!"

---

## Day 3: Loops (Doing Something Over and Over)

A **loop** tells the computer to repeat something. Instead of writing the same instruction 100 times, we just say "do this 100 times" or "keep doing this until something happens."

Two main types:

- **"Do this X times"** (FOR loop) — repeat a set number of times
- **"Keep doing this while..."** (WHILE loop) — repeat until something changes

### Let's Try It

> "Sometimes we want to do something over and over. Instead of saying it a million times, we can use a LOOP!"

**FOR loop:** Let's say Sparkle is trotting around a track. We want her to go around 3 times.

```
DO THIS 3 TIMES:
    Sparkle trots around the track
```

We don't say "trot, trot, trot." We just say "do it 3 times!"

**Math loop:** Let's count by ones!

```
Start at 1
DO THIS 5 TIMES:
    Say the number
    Add 1

(1... 2... 3... 4... 5!)
```

**WHILE loop:** What if we don't know exactly how many times? We keep going UNTIL something happens.

```
WHILE it is still raining:
    Wait and watch the sky

(When the rain stops and sun appears...)
Rainbow time!
```

The loop keeps going WHILE it's raining. When the rain stops, we "break out" of the loop and get our rainbow!

### Drawing Idea

Draw a circular arrow (like a recycling symbol) with a horse inside it. Write "go around 3 times" next to it.

---

## Day 4: Variables (Boxes That Hold Things)

A **variable** is like a labeled box that holds information. You give it a name, and you can put something inside (a number, a word, etc.). Later, you can look inside, change what's in it, or use it somewhere else.

### Let's Try It

> "In coding, we have special boxes called variables. We give each box a name, and we can put something inside!"

Let's make a box called "apples." This box holds how many apples Sparkle has eaten today.

```
apples = 0      (The box starts empty—zero apples!)

Sparkle eats an apple...
apples = 1      (Now there's 1 in the box!)

Sparkle eats another apple...
apples = 2      (Now there's 2!)
```

The box is called "apples," and the number inside changes!

**Rainbow example:**

```
rainbow_colors = 7

"How many colors in a rainbow?"
Look in the rainbow_colors box... it says 7!
```

**Math example:**

```
my_number = 5
my_number + 3 = ?

(Look in the box... 5! So 5 + 3 = 8!)
```

### Drawing Idea

Draw a box (like a shoebox) and write "apples" on the outside. Inside, write a number. Practice "changing" the number by erasing and writing a new one—this shows the variable updating!

---

## Day 5: Functions (Giving Instructions a Name)

A **function** is a set of instructions bundled together with a name. Instead of repeating all the steps every time, you just "call" the function by name, and it does all the steps for you.

Think of it like teaching someone a dance move and naming it. Once they know "The Rainbow Spin," you just say the name and they do all the steps!

### Let's Try It

> "Sometimes we do the same steps over and over. Instead of saying all the steps every time, we can give them a name! That's called a function."

Let's teach Sparkle a trick called "take_a_bow"!

```
FUNCTION take_a_bow:
    Bend front legs
    Lower head
    Stand back up
```

Now whenever we say "take_a_bow," Sparkle knows to do ALL those steps!

```
Sparkle, take_a_bow!

(Sparkle bends legs, lowers head, stands up)
```

**Rainbow example:**

```
FUNCTION draw_rainbow:
    Draw a red arch
    Draw an orange arch
    Draw a yellow arch
    Draw a green arch
    Draw a blue arch
    Draw a purple arch
```

Now we can just say "draw_rainbow" instead of listing every color!

### Drawing Idea

Draw Sparkle the horse. Draw a speech bubble that says "take_a_bow!" Then draw arrows showing each step Sparkle does.

---

## Day 6: Parameters (Giving Functions Extra Info)

Sometimes a function needs extra information to do its job. This extra info is called a **parameter**. It's like telling someone "make me a sandwich"—but they need to know WHAT KIND of sandwich!

### Let's Try It

> "Remember functions? Sometimes they need extra information. Like if I say 'feed Sparkle,' you might ask... feed her WHAT? That extra info is called a parameter!"

```
FUNCTION feed_sparkle(food):
    Pick up the food
    Give it to Sparkle
    Sparkle eats it!

feed_sparkle(apple)    --> Sparkle eats an apple!
feed_sparkle(carrot)   --> Sparkle eats a carrot!
feed_sparkle(hay)      --> Sparkle eats hay!
```

Same function, but we change what's in the parentheses (the parameter) to feed her different things!

**Rainbow example:**

```
FUNCTION paint_color(color):
    Dip brush in color
    Paint an arch

paint_color(red)       --> Red arch!
paint_color(orange)    --> Orange arch!
paint_color(yellow)    --> Yellow arch!
```

**Math example:**

```
FUNCTION add_five(number):
    Take the number
    Add 5
    Say the answer!

add_five(2)  --> 7!
add_five(10) --> 15!
add_five(0)  --> 5!
```

We made a function that adds 5 to ANY number we give it!

### Drawing Idea

Draw the feed_sparkle function like a machine: a box with a slot at the top (where you drop in the food) and Sparkle at the bottom eating. Label the slot "food goes here!"

---

## Putting It All Together

Let's get Sparkle ready for a ride and find a rainbow!

```
FUNCTION get_ready(animal):
    Put on saddle
    Put on bridle
    Climb on animal

horse_name = "Sparkle"

get_ready(Sparkle)

DO THIS 3 TIMES:
    Trot around the field

WHILE it is raining:
    Keep trotting under a tree

IF rain stops AND sun comes out:
    rainbow_colors = 7
    "Look! A rainbow with 7 colors!"
    Sparkle, take_a_bow!
```

Can you find each concept?

- **Sequence:** The order of steps
- **Loop:** Trotting 3 times, waiting while raining
- **Conditional:** Rain stops --> rainbow!
- **Variable:** horse_name, rainbow_colors
- **Function:** get_ready, take_a_bow
- **Parameter:** Sparkle (the animal we pass to get_ready)

---

## Quick Reference

| Concept | What It Means | Example |
|---|---|---|
| Sequence | Steps in order | 1. Saddle --> 2. Bridle --> 3. Ride! |
| Conditional | If this, then that | IF hungry --> THEN eat |
| Loop | Repeat! | Trot 3 times |
| Variable | A box with a name | apples = 5 |
| Function | Named instructions | take_a_bow! |
| Parameter | Extra info for a function | feed(carrot) |
