Section 7.2
String Operations
Learning Goals
Students will be able to explain and use concatenation
Students will be able to identify substrings
Students will evaluate expressions that manipulate strings (AAP-2.D)
AAP-2.D.1: String concatenation joins together two or more strings end-to-end to make a new string.Â
AAP-2.D.2: A substring is part of an existing string.
Objectives and Description
The objective of this lesson is to introduce students to two basic string operations: concatenation and substrings. Students will use concatenation to combine two drum beats: one created by their partner and one created by themselves.
Activities
Activity 7.2.1 (40 minutes)
Students form pairs and share their scripts from lesson 7.1 with each other
Each student will create 3 new strings in the script that was shared with them
Suggest some prep work in the step sequencer to plan out the drum beat
Encourage students to create a different drum beat than the one they used previously
Assign these 3 new strings to new variables & encourage commenting code to distinguish between the original code and the new code.
Students will use concatenation (the + operator) to combine two beat strings together and assign this to a new variable, then use these concatenated strings in makeBeat() to play the new drum beat
For example:
finalString = stringA + stringB
Students will do this for each part of the virtual drum kit and each resulting string should be 32 characters long
These strings should replace the original strings in the makeBeat() functions, which will result in a 2-measure drum beat being played