Students will learn to read App Lab’s API documentation and will use functions that accept parameters in order to complete a series of drawing puzzles which require them to make use of the App Lab API documentation to learn new drawing commands. Many of these commands will require the use of parameters. The final challenge asks students to design a personal monogram making use of the commands they learned during the lesson.
Students will be able to:- use parameters to provide different values as input to procedures when they are called in a program.- use API documentation to assist in writing programs.- define an API as the set of commands made available by a programming language.
Note: You will need to create a free account on code.org before you can view this resource.
In this lesson, students practice using and creating functions with parameters. Students learn that writing functions with parameters can generalize solutions to problems even further. Especially in situations where you feel like you are about to duplicate some code with only a few changes to some numbers, that is a good time to write a function that accepts parameters. In the second half of the lesson, students make a series of modifications to a program that creates an “Under the Sea” scene by adding parameters to functions to more easily add variation to the scene. Lastly, students are introduced to App Lab’s random number functions to supply random values to function calls so the scene looks a little different every time the program runs.
Students will be able to:- write functions with parameters to generalize a solution instead of duplicating code.- identify appropriate situations for creating a function with parameters.- use random numbers as inputs to function calls for the purpose of testing.- add parameters to a function in an existing piece of code to generalize its behavior.
In this lesson, students add variables to two different exemplary apps to keep track of a score or a count of some number of button clicks. The major topic is variable in scope and understanding the differences, benefits, and drawbacks, of using global versus local variables. This lesson focuses more on using global variables since in event-driven apps that’s what you need to keep track of data across multiple events.
The very basics of a simple if statement are also presented in this lesson, mostly to highlight the difference between the = and == operators. Finally, students are asked to apply what they’ve learned about variables, scope, and if statements, to make their own “clicker” game modeled after one of the exemplars they saw during the lesson.
Students will be able to:- use global variables to track numeric data in an app.- give a high-level explanation of what “variable scope” means.- debug problems related to variable scoping issues.- modify existing programs to add and update variables to track information.- create a multi-screen "clicker" game from scratch.
This lesson attempts to walk students through the iterative development process of building an app (basically) from scratch that involves the use of if statements. Following an imaginary conversation between two characters - Alexis and Michael - students follow the problem solving and program design decisions they make for each step of constructing the app. Along the way, they decide when and how to break things down into functions, and of course, discuss the logic necessary to make a simple game.
if
The last step - writing code that executes an end-of-game condition - students must do on their own. How they decide to use if statements to end the game will require some creativity. The suggested condition - first to score 10 points - is subtly tricky and can be written in many different ways.
At the conclusion of the lesson, there is three practice Create PT-style questions as well as resources explaining the connection between this lesson and the actual Create PT. Depending on how you use these materials they can easily add an additional day to this lesson.
Students will be able to:- write code to implement solutions to problems from pseudocode or description.- follow the iterative development process of a collaboratively created program.- develop and write code for conditional expressions to incorporate into an existing program.- write a large program from scratch when given directions for each step.
Students will extend the My Favorite Things app they built in the previous lesson so that it now manages and displays a collection of images and responds to key events. Students are introduced to the practice of refactoring code in order to keep programs consistent and remove redundancies when adding new functionality. As part of learning to use key events, students are shown that event handlers pass a parameter which contains additional information about the event. This lesson also serves as further practice at using arrays in programs.
Students will be able to:- use an array to maintain a collection of data in a program.- create apps that allow user interaction through key events.- refactor code in order to appropriately incorporate new functionality while maintaining readability and consistency.
In this lesson, students are introduced to the return command and learn to write their own functions that return values. Students first complete a simple unplugged activity based on the game Go Fish to introduce the concept of a return value. They will then complete a short sequence of exercises in Code Studio, which introduces preferred patterns for writing functions that return values. At the end of the sequence, students write and use functions that return values in a simple turtle driver app.
Students will be able to:- use the return command to design functions.- identify instances when a function with a return value can be used to contain frequently used computations within a program.- design functions that return values to perform frequently needed computations within a program.
Students continue to practice working with arrays and are introduced to a new user interface element, the canvas. The canvas includes commands for drawing simple geometric shapes (circles, rectangles, lines) and also triggers mouse and key events like any other user interface element. Over the course of the lesson, students combine these features to make an app that allows a user to draw an image while recording every dot drawn on the canvas in an array. By processing this array in different ways, the app will allow students to redraw their image in different styles, like random, spray paint, and sketching. Along the way, students use their knowledge of functions with return values to make code which is easy to manage and reuse.
Students will be able to:- programmatically control the canvas element in response to user interactions.- maintain a dynamically generated array through the running of a program in order to record and reuse user input.- use nested loops within a program to repeat a command on the same array index multiple times.- perform variable arithmetic within an array index to access items in an array by their relative position.