Unit 3 - Algorithms and Programming

This unit introduces the foundational concepts of computer programming, which unlocks the ability to make rich, interactive apps. This course uses JavaScript as the programming language, and App Lab as the programming environment to build apps, but the concepts learned in these lessons span all programming languages and tools.

Some of the lessons that follow have worksheets and student guides associated with activities. Those worksheets are listed in the relevant lesson plan, or you can check out all unit 3 student-facing activity guides here.

Chapter 1: Programming Languages and Algorithms

Big Questions

  • Why do we need algorithms?
  • How is designing an algorithm to solve a problem different from other kinds of problem solving?
  • How do you design a solution for a problem so that is programmable?
  • What does it mean to be a "creative" programmer?
  • How do programmers collaborate?

Enduring Understandings

  • 1.1 Creative development can be an essential process for creating computational artifacts.
  • 1.2 Computing enables people to use creative development processes to create computational artifacts for creative expression or to solve a problem.
  • 2.2 Multiple levels of abstraction are used to write programs or create other computational artifacts
  • 4.1 Algorithms are precise sequences of instructions for processes that can be executed by a computer and are implemented using programming languages.
  • 5.1 Programs can be developed for creative expression, to satisfy personal curiosity, to create new knowledge, or to solve problems (to help people, organizations, or society).
  • 5.2 People write programs to execute algorithms.
  • 5.3 Programming is facilitated by appropriate abstractions.

Week 1

Lesson 1: The Need for Programming Languages

Students write instructions for building a small arrangement of LEGO® blocks and trade with a classmate to see if they can follow them to construct the same arrangement. The lesson highlights the inherent ambiguities of human language deriving the need for a well-defined programming language which leaves no room for interpretation.

Student Links: Video | Activity Guide | Activity Guide |

Lesson 2: The Need for Algorithms

Students develop (and are eventually provided with) commands for a "Human Machine Language" designed to perform operations on playing cards. The lesson highlights the connection between programming and algorithms by showing that different techniques for solving the same problem can be expressed in the language.

Teacher Links: Answer Key | Answer Key Student Links: Activity Guide | Activity Guide

Lesson 3: Creativity in Algorithms

Concept Invention | Unplugged | Algorithms

Students continue to work with the “Human Machine Language” - with an added SWAP command - to design an algorithm to move the minimum card to the front of the list. Students may design more algorithms for other problems and challenges provided.

Teacher Links: Answer Key Student Links: Activity Guide | Video

Week 2

Lesson 4: Using Simple Commands

Turtle Programming

Students use the App Lab programming environment for the first time and become acquainted with the turtle. The chief problem is to find the most “efficient” way to draw an image of a 3x3 grid using a limited set of only 4 commands.

Teacher Links: Multiple Choice Student Links: Video |

Lesson 5: Creating Functions

Turtle Programming

Students learn to define and call their own procedures (or “functions”) in order to create and give a name to a group of commands for easy and repeated use in their code. Named procedures are a form of abstraction that enable the programmer to reduce complexity by removing details and generalizing functionality.

Teacher Links: Multiple Choice Student Links: | Video

Lesson 6: Functions and Top-Down Design

Turtle Programming

Students learn about top-down design strategies for solving more complex programming problems by breaking the problem down into small parts that can be named and represented as functions. The code in the resulting program should read more like a description of how to solve the problem than like raw code.

Student Links: | Worksheet

Week 3

Lesson 7: APIs and Using Functions with Parameters

Students read and use App Lab’s API documentation to learn about new turtle commands that they must use to complete a series of drawing puzzles.

Student Links:

Lesson 8: Creating Functions with Parameters

Students practice using and creating functions with parameters by making a series of modifications to a program that creates an “Under the Sea” drawing. Students add parameters to generalize behavior that can vary, and make use of App Lab's randomNumber function add variation to the scene.

Student Links: Video

Lesson 9: Looping and Random Numbers

Turtle Programming

Students learn to use a simplified version of a for loop to add repetition to their code (i.e. repeat x times loop). Calling functions repeatedly with a loop combined with random numbers enables students to create more complex and varied drawings for digital scenes.

Teacher Links: Forum | Multiple Choice Student Links: | Video

Week 4

Lesson 10: Practice PT - Design a Digital Scene

Turtle Programming

Students work in groups of 3 or 4 to design and write the code for a program that draws a digital scene of their choosing. Students break the scene down into small parts and divvy up the code writing amongst the team. Each individual's code is combined at the end to create the full scene. The project concludes with written reflection questions similar to those students will see on the AP® Performance Tasks.

Student Links: | |

Chapter Commentary

Unit 3 Chapter 1 - What’s the story?

The underlying story to this chapter is that programming is a creative endeavor, and a form of personal expression about how to get a machine to solve problems. The first three lessons we use unplugged activities to highlight the connections between algorithms, human language, and programming languages. The remainder of the unit we spend writing programs in App Lab using the classic “turtle”, or an arrow that you can control with code to create drawings. While students will learn the basic syntax of JavaScript, the main focus is on top-down design and problem solving strategies.

In the unplugged activities we derive the need for programming languages first, and then focus on how to express algorithms using them. Algorithms are building blocks for solving computational problems. You can design them to solve individual small tasks and then combine them and recombine them to solve others. Furthermore, there is a good deal of creativity involved in designing algorithmic solutions to problems. It may come as a surprise that, given only a few machine instructions and a simple problem, two people may write code to solve it in completely different ways. This might be because their overall approach (algorithm) is different or simply because they went about writing code to express it differently.

When we shift to solving problems with code in App Lab, we hold the context of the problem (solving turtle drawing problems) constant in order to focus on problem-solving behaviors and techniques students can use with JavaScript. In particular we want to emphasize managing complexity with abstraction. This entails breaking a problem down into its constituent parts, writing functions to solve each part individually, and then combining them together to solve the overall problem. Students should be very familiar with the general ideas behind “top-down” design from the previous units of study. Just like figuring out a way to encode a complex piece of information in binary, computer programs can be thought of as complex systems that can be broken down repeatedly to gain insight into the subsystems that make it up.

Our approach to the Content

To call programming a creative form of personal expression sounds counterintuitive to a lot of beginners. Our hope is that this fact resonates with new students since we see it as illustrating our teaching philosophy of computer-science-as-a-liberal-art. The mindset is expressed eloquently by Donald Knuth: “Instead of imagining that our main task is to instruct a computer what to do, let us concentrate rather on explaining to human beings what we want a computer to do.” It is with this sentiment in mind that we start the unit by doing just that - writing out algorithms to be executed by hand to gain insights into what makes programming challenging and creative. The unplugged activities reveal why programming languages need to exist, and foreshadow some of the ideas that come later in this unit and throughout the course. They serve as a common point of reference that many future lessons can be tied back to.

Our sequence of lessons to introduce programming is a little unconventional, especially our choice to place early emphasis on writing functions and procedural abstraction, but there is a method to the madness. A major skill that programmers have is the ability to look at a problem and know how to break it down into smaller and smaller parts that can be more easily programmed into reusable procedures. In JavaScript, procedures are called “functions”, and the generic term for encapsulating the solution to a problem in a named procedure is called “procedural abstraction.” We focus on functions and procedural abstraction for three main reasons: (1) we want to keep the focus on problem solving and collaboration rather than getting lost in syntax, (2) we are reinforcing the enduring understandings that multiple levels of abstraction are used to write program, and (3) just to be practical, the interactive event-driven apps we make in Unit 5 require a solid foundation in writing functions.