Music and Variables

Students learn how to use variables, a more flexible form of repetition, to create a musical composition. This lesson is split across two days.

Duration: 2 hours
Required Materials: Laptops, projector with speakers
MA DLCS Standards: 6-8.CT.b.3, 9-12.CT.a.1


The big idea


Students will be able to…


Progression


Key vocabulary


Lesson plan

  1. Warm up: Music video (5 mins) — As a class, watch Twinkle Twinkle Little Star (0:00–1:00). Pay attention to the repetition in the song. Then, listen to the song a second time and write down the pattern using letters of the alphabet (A, B, C, …). Review with a partner and then as a class.

    Explain that today, students will be creating their own music in Wipple. Discuss whether they think they could use repeat to play Twinkle Twinkle Little Star. Why or why not? Explain answers.

  2. Guided practice: Setting up music and variables (10 mins) — Direct students to open their computers to wipple.org and create a new playground. Instead of clicking on Turtle, click Music. Demonstrate how to create a melody and change the variable name, and how to use the play command to change the instrument. Students follow along to create their own simple melody.

  3. Activity: Composition (75-90 mins) — Students create a composition of their own with a partner. The composition must contain at least three variables, two instruments, and one use of repeat. Switch who is using the computer every 15 minutes so that both partners have a chance to write code. This part of the lesson takes place over two days. (When students arrive the next day, invite a few groups to share what they have for inspiration.)

  4. Presentations (15 mins) — Partner groups present their composition to the class and explain their process.

  5. Exit ticket (3 mins) — Have students click Print to save a PDF of their code, and save their song as an audio file. Students upload both files and answer the questions in the slideshow on their own. You may use a Google Form or other online survey.


Extensions


Universal design


Worked example: Simple melody

  1. Drag in the melody : [♪] command from the sidebar. Click on the music note and experiment with the piano.

  2. Change the name of the variable from melody to a name that describes your melody more specifically. For example, if the melody is from a song, the variable may be the song’s name. (Note: If the variable contains multiple words, they must be separated with a dash -.)

  3. Drag in the play command and change it to refer to your variable. Change the instrument to tuba.

  4. Press Run to hear your melody played by a tuba.

Result:

my-song : [♪]
play [tuba ▾] my-song

Worked example: Drawing with variables alternate assignment

  1. Create a variable named size containing (50 pixels).

  2. Create a second variable named sides containing the number of sides of the shape.

  3. Recall the formula for the angle between two sides of a shape: (360 degrees) / sides. Create a third variable named angle to represent this.

  4. Use repeat to draw the shape corresponding to your variables. Adjust size and sides, and observe how the shape changes.

  5. Ask the student to explain how the use of variables makes the code easier to understand. Variables are a form of abstraction over the specific quantity your code works with; they let you give names to numbers and other items.

Result:

size : (50 pixels)
sides : 4
angle : (360 degrees) / sides
repeat (sides times) {
  forward size
  left angle
}

Sample student responses