Lesson 9: Songwriting
50 minutes
Overview
This context-setting lesson will help students understand why combining chunks of code into functions can be a helpful practice.
Purpose
The use of functions helps simplify code and develop the student's ability to organize their program. Students will quickly recognize that writing functions can make their long programs easier to read and easier to debug if something goes wrong.
Standards
AP - Algorithms & Programming
- 1B-AP-08 - Compare and refine multiple algorithms for the same task and determine which is the most appropriate.
- 1B-AP-11 - Decompose (break down) problems into smaller, manageable subproblems to facilitate the program development process.
Agenda
Objectives
Students will be able to:
- Describe how functions can make programs easier to write.
- Identify sections of a song to pull into a function.
- Locate repeating phrases inside song lyrics.
Preparation
- (Optional) Watch the *Lesson in Action Video.
- Print several *worksheets for each group.
- Print one *assessment for each student.
- Secure access to songs and lyrics for activity.
- Make sure every student has a journal.
Links
Heads Up! Please make a copy of any documents you plan to share with students.
For the teachers
- CSF - Course E - Slides 2022-2023 - Slides (Download)
- Functions Unplugged: Songwriting - Lesson in Action Video
- Functions Unplugged: Songwriting - Assessment Answer Key
For the students
- Functions Unplugged: Songwriting - Worksheet
- Functions Unplugged: Songwriting - Assessment
- Songwriting with Functions - Unplugged Video (Download)
Vocabulary
- Function - A piece of code that you can call over and over again.
Teaching Guide
Warm Up (20 minutes)
Introduction
Display: Show “Reflect” slide
Reflect: What is the chorus to your favorite song?
Vocabulary
Display: Show “Vocabulary” slide
This lesson has one new and important word:
- Function - A piece of code that you can call over and over again.
Sing a Song
Display: Show “Baby Shark” slide
- Let the class know that today is song day!
- We're going to learn a song together.
- Start with a simple song, either written out or projected on the screen.
- Point to the chorus and be sure that the class knows how it goes before you begin on the song.
- Blast through the song, singing it with them in the beginning, then see what happens when you get to the part where it calls the chorus.
Baby Shark is being used here as an example only. If your students know this song, feel free to use it. Otherwise, choose an appropriate song that they might be more familiar with (either from music class or the radio.)
Key Gestures:
Baby shark: make a shark mouth with finger and thumb.
Mommy shark: make a mouth with both hands, opening at the wrist.
Daddy shark: make a big mouth with both of your arms.
Grandma shark: like mama shark, but with fingers curled in.
Grandpa shark: like papa shark, but with fingers curled in.
Hungry shark: one hand on head like a fin, rubbing tummy with the other hand.
Little fish: both hands together with fingers pointing forward, move from side to side.
Swim away: pretend to swim.
Safe at last: wipe forehead, and flick hand like removing sweat.
Chorus:
doo doo, doo doo doo doo
Song:
Baby Shark
Chorus
Baby Shark
Chorus
Baby Shark
Chorus
Baby Shark
Mommy Shark
Chorus
Mommy Shark
Chorus
Mommy Shark
Chorus
Mommy Shark
Daddy Shark
Chorus
Daddy Shark
Chorus
Daddy Shark
Chorus
Daddy Shark
(Continuing on, if time permits, with "Grandma shark", "Grandpa shark", "Hungry shark", "Little fish", "Swim away", "Swim faster", "Safe at last".)
- It's quite likely that the majority of the class will sing the lyrics for the chorus when you point to that bit.
- Stop the song once that happens, and explicitly highlight what just happened.
- You defined the chorus.
- You called the chorus.
- They sang the chorus.
- Stop the song once that happens, and explicitly highlight what just happened.
Display: Show “Discuss” slide
- Ask the class why they suppose you only wrote the chorus once at the top of the paper instead of writing it over and over in each place where it is supposed to be sung.
- What are other benefits of only writing the chorus once when you sing it many times?
Call out the difference between a function (“doo doo”) and a loop (“baby shark doo doo” x 3) - or ask your students if they can tell you the difference between them.
To hit this point home, you can look up the lyrics for some popular songs on the Internet. Show the students that the standard for repeating lyrics is to define the chorus at the top and call it from within the body of the song.
Now, imagine that this song is a computer program. Defining a title (like "chorus") for a little piece of code that you use over and over again is called creating a function.
This is helpful to computer scientists for some of the same reasons that it is helpful to songwriters.
- It saves time not having to write all the code over and over in the program.
- If you make a mistake, you only have to change it one place.
- The program feels less complicated with the repeating pieces defined just once at the top.
We are going to play with songs a little more, to try to really understand how often this technique is used!
Main Activity (20 minutes)
Songwriting
A fantastic way to compare functions to something we see in our everyday lives is to look at songs. Songs often have certain groups of lyrics that repeat over and over. We call such a group a "chorus."
It's most exciting for students to do this lesson with popular music from the radio, but if you're having a hard time finding appropriate songs where the lyrics repeat exactly, here are a few timeless options:
Display: Show “Songwriting” slide
Directions:
- Divide into groups of 4, 5, or 6.
- Give each group several copies of the *Songwriting Worksheet.
- Play a short song for the class that contains a clear chorus that does not change from verse to verse.
- Challenge the class to identify (and write down) the chorus.
- Compare results from each group.
Did everyone get the same thing? Sing your choruses together to find out! Play this game over and over until the class has little trouble identifying the choruses.
- It is often easier just to have the class listen to (or watch) the song, then vote on what the chorus is by singing it together, rather than writing the whole thing down. If you choose this method, consider having the class do a written chorus for the final song selection to be sure that the visual learners get proper reinforcement.
Wrap Up (5 minutes)
Reflection
Display: Show “Discussion” slide
Flash Chat questions are intended to spark big-picture thinking about how the lesson relates to the greater world and the students' greater future. Use your knowledge of your classroom to decide if you want to discuss these as a class, in groups, or with an elbow partner.
Flash Chat: What did we learn?
- Would you rather write lyrics over and over again or define a chorus?
- Do you think it's possible to make multiple choruses for the same song?
- Does it make sense to make a new chorus for every time it's needed in a song?
Display: Show “Reflect” slide
Reflect: Can you think of another activity (besides songwriting) where you might want to call a special group of instructions several times?
Assessment (5 minutes)
Display “Songwriting Assessment” slide.
Hand out the *Songwriting Assessment worksheet and allow students to complete the activity independently after the instructions have been well explained. This should feel familiar, thanks to the previous activities.
Extended Learning
Use these activities to enhance student learning. They can be used as outside of class activities or other enrichment.
Functional Suncatchers Visit the CS Fundamentals Unplugged Table or click on the link for Functional Suncatchers. This activity does take a few supplies from the craft store, but it helps students to see the value of calling multiple functions.
Create Your Song
- Start by creating a chorus together, then repeat it between verses of a song that you develop around it.
- Make a change to the chorus, and ponder how much easier it is to change in just one place.
- Change the chorus again, making it much longer than it was originally.
- Add a second chorus and alternate between them in your verses.
Songwriting a Program
- What if we acted out songs instead of singing them? All of a sudden, our chorus would be a function of repeated actions, rather than words.
- Use the concepts of the arrows from the Graph Paper Programming lesson and create a program with lots of repeating instructions.
- Circle those repeating actions so that the class can see where they are.
- Define a function called "Chorus" above the program.
- Cross out everywhere the repeating actions appear in the program and write "Chorus" instead.
- Repeat until the class can go through this process with little direction.
Cross-Curricular Opportunity
Fossil Fact Rap (45-60 minutes)
Computer Science + English Language Arts + Science
Fossil Fact Rap is an optional activity aligned to Common Core ELA and Next Generation Science Standards, written by our teacher community. Students will expand their knowledge of functions to write a rap using academic terminology and facts related to fossils and rock layers. They will then learn how to “call a function” using the provided “defined function,” or rap song’s hook.
Standards Addressed:
-
CCSS.ELA-LITERACY.W.4.2.D: Use precise language and domain-specific vocabulary to inform about or explain the topic.
-
CCSS.ELA-LITERACY.W.4.7: Conduct short research projects that build knowledge through investigation of different aspects of a topic.
-
CCSS.ELA-LITERACY.SL.4.5: Add audio recordings and visual displays to presentations when appropriate to enhance the development of main ideas or themes.
-
NGSS.4-ESS1-1: Identify evidence from patterns in rock formations and fossils in rock layers to support an explanation for changes in a landscape over time.
This work is available under a Creative Commons License (CC BY-NC-SA 4.0).
If you are interested in licensing Code.org materials for commercial purposes contact us.