Time needed: 30 minutes
Materials needed:
Setup:
Writing songs is a complicated process, but it can be broken into a sequence of steps or an algorithm. An algorithm is a series of specific instructions that can be applied to many situations. For example, a step-by-step recipe or a set of directions from one place to another are two examples of algorithms you might already use!
JavaScript is one of the fundamental programming languages used online. It’s used to make programs interactive. Whenever you do something on a website that’s interactive, such as clicking a button, playing a videogame, or seeing an ad pop up, that code was written in JavaScript. A function is one of the basic building blocks of a program. It’s a type of instruction that’s similar to a verb: a function does something.
When programmers start working on a new idea, they often sketch out their ideas on paper before they move on to coding their algorithms on a computer. Pseudocode is a way to plan a computer program using human-friendly language. It’s not actual coding, but rather a written description of the key elements of an algorithm or program. It’s used as a quick way of thinking about a program without completely writing it out in code. It saves time and still lets a programmer check that their program will run.
Activity:
For this activity, you’re the programmer! Translate a song into a short program of three or more functions to make an algorithm. Then, give the algorithm to someone else who will use it to sing the song.
Note: If you don’t have a partner for the activity, that’s okay! You can follow your coded algorithm to sing the song on your own.
First, check out pages 1 and 2 of the Song Functions handout. Make sure you understand what functions, arguments, and variables are and how to write them with the correct syntax. Look at the examples that work as well as those that don’t!
Next, you’re going to translate a set of song lyrics into code. To get started, choose a song that promotes positive social change. All kinds of music, from folk to hip-hop to rock ’n’ roll to country, have included lyrics that send messages of equality and positive change. For example:
Once you’ve chosen a song, write down the lyrics on a sheet of paper and brainstorm how you can translate them into pseudocode:
Rewrite the lyrics on page 3 of the Song Functions handout, breaking the song into different pieces. Then, translate each part using the sing() function.
As you write your program, make sure to use functions, arguments, and variables. Remember to be as specific as possible—once you hand over your algorithm, the “computer” won’t be able to ask questions and you won’t be able to provide any additional instructions!
After you’ve translated the song, share your program with someone else who can play the role of a computer and sing the song by following the instructions. If you don’t have a partner, that’s okay—just follow your own instructions, step by step, to see if you can sing the song correctly.
If the computer” doesn’t follow the instructions correctly, that’s okay. It might take multiple tries to code the song correctly, so mistakes are to be expected. In computer programming, getting code right is a learning process—you can expect to make mistakes, but also know that you can fix them. In fact, sometimes a mistake leads to unexpected results!
And that’s it! Now that you’ve translated the song into code, you could give the program to someone else (or a computer!) to follow and sing the song.
This activity reminds us how a complex activity, such as writing a song, can be broken down into a sequence of individual actions or an algorithm. Using an algorithm helps because it’s efficient and general. The functions are simple enough to describe one part of the song and can also be reused—think of the sing() function. Once coded, the program can be shared with someone else or run by a computer.