Students will determine the situations in which specific list operations are the most useful
Students will use list operations to access and modify data
The objective of this lesson is to further student understanding of lists by giving them more exposure to some additional list operations. Students are tasked with modifying a script that is provided to them by using the correct list operations for a given task.
Activity 6.2.1 (50 minutes)
After a period of instruction in which the teacher goes over the different list operations, students will receive a script that contains pre-written code that they must modify to satisfy the conditions listed in the comments. The end result will be a functioning script that produces a song when it is compiled and run.
Student tasks:
Append - students will add new sounds to the end of an existing list
Insert - students will add new sounds to an existing list at a specified index
Remove - students will remove an element from a specified index
Length - students will evaluate the length of a given list and use the returned value in code
Students will create a string using numbers 0-x and the characters - and +, where x is the last index of a given list. This is a new version of the beat string that they should be familiar with
makeBeat() normally plays a given sound whenever a 0 occurs in a beat string, but if a list is used as the input for makeBeat(), numbers 0-x will access the corresponding element in the list, which in this case will be a drum sound
This allows students to create more complex drum beats or use multiple sounds for the same rhythm (example: open and closed hi-hat can now be combined into a single makeBeat() call and beat string rather than two separate ones)