Lesson 10: Building an App: Color Sleuth

Overview

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.

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 many different ways.

At the conclusion of the lesson there are 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.

Purpose

The purpose here is for students to see how "experts" would approach writing an app from scratch when all you have to start out with is a sketch on paper of some idea. Research has shown that what novices often need is an expert walk-through to explain the rationale behind certain decisions and to see the kinds of problems they anticipate and solve. There are a few key things that happen in this lesson that we hope students see and take to heart:

  • There is no one "correct" way to approach writing a program
  • You don't write programs "in order" from top to bottom - you write in pieces and organize the code into sections and functions.
  • Start with a small problem to solve - solve it and move to the next one
  • Use a buddy or "thought partner" to talk things through
  • Sketch out pseudocode on paper to get your thoughts straight
  • If you get stuck, there is always something small you can do to make progress

After this lesson students are prepared to complete the AP Create PT. If you have more time in your year you may continue through Unit 5 Chapter 2 before beginning the task. When you decide to begin the task use the materials in the AP Create PT Prep unit to further prepare students. For more details refer to pages 32 and 33 of the CSP Curriculum Guide .

Agenda

View on Code Studio

Objectives

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

Links

Heads Up! Please make a copy of any documents you plan to share with students.

For the Students

Vocabulary

  • Boolean Expression - in programming, an expression that evaluates to True or False.
  • Conditionals - Statements that only run when certain conditions are true.
  • If-Statement - The common programming structure that implements "conditional statements".
  • Selection - A generic term for a type of programming statement (usually an if-statement) that uses a Boolean condition to determine, or select, whether or not to run a certain block of statements.

Introduced Code

Teaching Guide

Getting Started (20 Minutes)

Remarks

In this lesson you're going to build an app from scratch, but you'll have guidance and help. The app you'll make will require you to apply all of the skills you've learned so far:

  • Adding event handlers
  • Using variables
  • Breaking problems down into functions
  • Using if statements

In the lesson, you'll follow the path of two imaginary students - Alexis and Michael - as they walk through each of the problems that have to get solved along the way. They'll do the thinking and problem solving, you'll write the code.

This project will mirror many of the elements of the Create PT which we'll look into more deeply at the end of the project. At the end of this project you should know all the programming skills you'll need to complete that task.

Here is what you're going to make...

What are you worried about? Where to Start?

Show this image of the sketch mock-up of the app.

  • Students can also find it in code studio in the lesson introduction.

With this image on display...

Prompt:

"Looking at just this sketch of the app with its few notes about what it's supposed to do...What are you thinking?...What are you worried about?...Are there elements of this that you're not sure you know how to program?"

With an elbow partner write down two things:

  1. Make a quick list of things you're not sure you know how to program yet, or things you're worried about.
  2. What would be the first thing you'd try to get working? (Assume that all of the design layout is done -- what's the first code you'd write to get things started?)

Discussion Goal

This is an informal way to do the first part of a KWL (Know, Want-to-know, Learned) Chart. You can do a formal one for this lesson if you think it would be helpful.

The point of the conversation here is really just to activate students' thinking about what they do and don't know.

For things they don't know or they're worried about you can assure them that techniques for doing those things are revealed in the lesson

For where they should start encourage students to start with what they know, rather than what they don't. A good way to make progress on an app is start by adding things they know first since that will help get them started.

Let students discuss with their partners for a few minutes.

Open discussion to the group: What are you worried about? Where would you start?

Possibilities for "Worried about:"

  • Making random colors with code
  • Choosing a random button to make a different color
  • Knowing whether the user clicked the "right" button or not
  • Switching player turns
  • Keeping track of whose turn it is - and the score
  • How does the game end?

Possibilities for "Where to start":

  • NOTE: almost anything is possible, encourage students to start with things they know rather than things they're worried about, like:
  • Adding event handlers for the button clicks
  • Adding a variable (or two) to keep score
  • Can they use what they know about randomNumber to generate these random colors? -- worth looking into.

Activity (80 Minutes)

Transition to Code Studio

Students can work individually or with a partner

  • As usual, we recommend that students at least have a coding buddy - someone they can work with and ask questions of as they work through the exercises.
  • It's also reasonable to have students pair-program during this lesson, switching off writing the code at each level.

Code Studio levels

View on Code Studio

Teaching This Lesson

This lesson looks like it has a lot of reading. The reading should go fairly fast since it's written like a script of two people talking.

You can think about your pause points in this lesson, where you might gather everyone to check for understanding, or at least do a check-in with various groups.

  • There are a few unavoidably tricky steps in the latter half of the lesson - steps that require students to modify or add to the code in more than one place in order to see the next thing. It's worth verifying that students have successfully completed these before moving on.

You might also consider reading out loud some parts of the script - particularly some the tricker decision-making points - to make sure students understand what decision was made and why.

  • It's also important to acknowledge along the way what's recapped in the Epilogue - that what we're walking students through here is NOT the one true correct way to make this app. Each decision, while well-reasoned, is relatively arbitrary.
  • The goal of the script is to provide a model for collaboration, thinking about problems in small pieces, and how a process of iterative development can lead to a robust project.
  • Using setProperty
  • (click tabs to see student view)
  • How to Pick a Random Button
  • (click tabs to see student view)
  • How to Make a Random Color
  • (click tabs to see student view)
  • Functions in Your Color Sleuth App
  • (click tabs to see student view)
  • Activating Buttons
  • (click tabs to see student view)
  • How to Switch Player Turns
  • (click tabs to see student view)
  • Updating the Score
  • (click tabs to see student view)
View on Code Studio

This is probably going to be the hardest level because there is the least amount of guidance.

Also, the end game condition can be written a number of different ways. Even for a particular condition like "first to 10" there are several different ways you could go about it. This is intentional in order to spur actual problem solving, and encourage students to talk to each other about possible solutions.

Encourage students to: Study the pseudocode diagram from the previous page - it has the outline of what you need to add to the code Don't forget to add a little bit and test with console.log statements * Ask a friend for help.

2 possible ways to write the checkGameOver function are provided as examples in the teacher panel - each using a different technique of if-statements that we learned about.

View on Code Studio

Use this epilogue as the foundation for wrap up. Either have students read it, review it out loud.

  • AP Practice Responses - Algorithms and Abstraction
  • (click tabs to see student view)

Wrap Up (15-50 mins)

Gallery Walk (Optional)

  • In theory students made some of their own personal modifications - you can do a gallery walk to share
  • You can also gallery walk to look at and appreciate code for the end-of-game conditions.

Review the Epilogue

  • The last level in code studio contains some text about the app development walk through. Students don't have to read it, but you should review its key points about:

  • how and why writing code is a creative process

  • There is no one correct way to do things
  • The realistic parts of Alexis and Michael's conversation

Teaching Tip

Ready for the Create PT: After completing this lesson students will have the minimum skills they need to complete the AP Create PT. Time permitting you should continue through Unit 5 Chapter 2 and get as far as you can before starting the Create PT - the more programming students have under their belts the better.

When you do opt to begin it, students should use the materials in the AP Create PT Unit to prepare. You can find it as a unit in the dropdown menu to assign to your section in the teacher dashboard.

Connections to the AP Create Performance Task

Distribute: Color Sleuth and the AP Create PT - AP Explanation (students can find a link on Level 1 of this lesson)

  • This document explains how the elements of this project, and the process, map to each requirement for the AP Create PT.

  • Point out to students that if they had gone through a similar process as Alexis and Michael that this project basically meets the requirements of the AP Create Performance Task. The trick would be provide written responses that properly highlight everything.

  • You could optionally have students practice writing responses to the real AP Create Task writing prompts using this document as a guide.

Other Create PT Options and Resources:

  • There are three questions (bubbles) at the end of this lesson in style of the Create PT. They use the color sleuth project as an example as though it were submitted for the Create PT. Two questions address algorithms and one is a refresher on abstraction.

  • Optionally pull out the AP Digital Portfolio Student Guide - Resource so that you can have it on hand to review the different components of the Create PT.

  • Optionally head over to the AP Create Task Prep Unit if you'd like to go more in depth with Create Task review at this point.

Review if statements for assessment

The stage that follows this one is an assessment the covers if-statements. You can review the kinds of "toy" problems that appear in the AP Assessment, many of which are similar to the kinds of problems students did in the exercises in lessons prior to this one.

That includes the unplugged "will it crash?" exercises. You might look at those again for review.

Standards Alignment

View full course alignment

Computer Science Principles

1.1 - Creative development can be an essential process for creating computational artifacts.
1.1.1 - Apply a creative development process when creating computational artifacts. [P2]
  • 1.1.1A - A creative process in the development of a computational artifact can include, but is not limited to, employing nontraditional, nonprescribed techniques; the use of novel combinations of artifacts, tools, and techniques; and the exploration of personal cu
  • 1.1.1B - Creating computational artifacts employs an iterative and often exploratory process to translate ideas into tangible form.
1.2 - Computing enables people to use creative development processes to create computational artifacts for creative expression or to solve a problem.
1.2.1 - Create a computational artifact for creative expression. [P2]
  • 1.2.1A - A computational artifact is anything created by a human using a computer and can be, but is not limited to, a program, an image, audio, video, a presentation, or a web page file.
  • 1.2.1B - Creating computational artifacts requires understanding and using software tools and services.
  • 1.2.1C - Computing tools and techniques are used to create computational artifacts and can include, but are not limited to, programming IDEs, spreadsheets, 3D printers, or text editors.
  • 1.2.1D - A creatively developed computational artifact can be created by using nontraditional, nonprescribed computing techniques.
  • 1.2.1E - Creative expressions in a computational artifact can reflect personal expressions of ideas or interests.
1.2.3 - Create a new computational artifact by combining or modifying existing artifacts. [P2]
  • 1.2.3A - Creating computational artifacts can be done by combining and modifying existing artifacts or by creating new artifacts.
  • 1.2.3C - Combining or modifying existing artifacts can show personal expression of ideas.
1.2.4 - Collaborate in the creation of computational artifacts. [P6]
  • 1.2.4A - A collaboratively created computational artifact reflects effort by more than one person.
  • 1.2.4C - Effective collaborative teams practice interpersonal communication, consensus building, conflict resolution, and negotiation.
  • 1.2.4D - Effective collaboration strategies enhance performance.
  • 1.2.4E - Collaboration facilitates the application of multiple perspectives (including sociocultural perspectives) and diverse talents and skills in developing computational artifacts.
  • 1.2.4F - A collaboratively created computational artifact can reflect personal expressions of ideas.
1.2.5 - Analyze the correctness, usability, functionality, and suitability of computational artifacts. [P4]
  • 1.2.5D - The suitability (or appropriateness) of a computational artifact may be related to how it is used or perceived.
2.2 - Multiple levels of abstraction are used to write programs or create other computational artifacts
2.2.1 - Develop an abstraction when writing a program or creating other computational artifacts. [P2]
  • 2.2.1A - The process of developing an abstraction involves removing detail and generalizing functionality.
  • 2.2.1B - An abstraction extracts common features from specific examples in order to generalize concepts.
4.1 - Algorithms are precise sequences of instructions for processes that can be executed by a computer and are implemented using programming languages.
4.1.1 - Develop an algorithm for implementation in a program. [P2]
  • 4.1.1A - Sequencing, selection, and iteration are building blocks of algorithms.
  • 4.1.1C - Selection uses a Boolean condition to determine which of two parts of an algorithm is used.
4.1.2 - Express an algorithm in a language. [P5]
  • 4.1.2G - Every algorithm can be constructed using only sequencing, selection, and iteration.
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.1.1 - Develop a program for creative expression, to satisfy personal curiosity, or to create new knowledge. [P2]
  • 5.1.1A - Programs are developed and used in a variety of ways by a wide range of people depending on the goals of the programmer.
  • 5.1.1B - Programs developed for creative expression, to satisfy personal curiosity, or to create new knowledge may have visual, audible, or tactile inputs and outputs.
  • 5.1.1C - Programs developed for creative expression, to satisfy personal curiosity, or to create new knowledge may be developed with different standards or methods than programs developed for widespread distribution.
  • 5.1.1D - Additional desired outcomes may be realized independently of the original purpose of the program.
5.1.2 - Develop a correct program to solve problems. [P2]
  • 5.1.2A - An iterative process of program development helps in developing a correct program to solve problems.
  • 5.1.2B - Developing correct program components and then combining them helps in creating correct programs.
  • 5.1.2C - Incrementally adding tested program segments to correct, working programs helps create large correct programs.
  • 5.1.2D - Program documentation helps programmers develop and maintain correct programs to efficiently solve problems.
  • 5.1.2E - Documentation about program components, such as blocks and procedures, helps in developing and maintaining programs.
  • 5.1.2F - Documentation helps in developing and maintaining programs when working individually or in collaborative programming environments
  • 5.1.2G - Program development includes identifying programmer and user concerns that affect the solution to problems.
  • 5.1.2H - Consultation and communication with program users is an important aspect of program development to solve problems.
  • 5.1.2I - A programmer’s knowledge and skill affects how a program is developed and how it is used to solve a problem.
  • 5.1.2J - A programmer designs, implements, tests, debugs, and maintains programs when solving problems.
5.1.3 - Collaborate to develop a program. [P6]
  • 5.1.3A - Collaboration can decrease the size and complexity of tasks required of individual programmers.
  • 5.1.3B - Collaboration facilitates multiple perspectives in developing ideas for solving problems by programming.
  • 5.1.3C - Collaboration in the iterative development of a program requires different skills than developing a program alone.
  • 5.1.3D - Collaboration can make it easier to find and correct errors when developing programs.
  • 5.1.3E - Collaboration facilitates developing program components independently.
  • 5.1.3F - Effective communication between participants is required for successful collaboration when developing programs.
5.2 - People write programs to execute algorithms.
5.2.1 - Explain how programs implement algorithms. [P3]
  • 5.2.1A - Algorithms are implemented using program instructions that are processed during program execution.
  • 5.2.1B - Program instructions are executed sequentially.
  • 5.2.1C - Program instructions may involve variables that are initialized and updated, read, and written
  • 5.2.1D - An understanding of instruction processing and program execution is useful for programming.
5.3 - Programming is facilitated by appropriate abstractions.
5.3.1 - Use abstraction to manage complexity in programs. [P3]
  • 5.3.1A - Procedures are reusable programming abstractions.
  • 5.3.1B - A function is a named grouping of programming instructions.
  • 5.3.1C - Procedures reduce the complexity of writing and maintaining programs.
5.4 - Programs are developed, maintained, and used by people for different purposes.
5.4.1 - Evaluate the correctness of a program. [P4]
  • 5.4.1C - Meaningful names for variables and procedures help people better understand programs.
  • 5.4.1D - Longer code blocks are harder to reason about than shorter code blocks in a program.
  • 5.4.1E - Locating and correcting errors in a program is called debugging the program.
  • 5.4.1F - Knowledge of what a program is supposed to do is required in order to find most program errors.
  • 5.4.1G - Examples of intended behavior on specific inputs help people understand what a program is supposed to do.
5.5 - Programming uses mathematical and logical concepts.
5.5.1 - Employ appropriate mathematical and logical concepts in programming. [P1]
  • 5.5.1D - Mathematical expressions using arithmetic operators are part of most programming languages.
  • 5.5.1E - Logical concepts and Boolean algebra are fundamental to programming.

CSTA K-12 Computer Science Standards (2017)

AP - Algorithms & Programming
  • 2-AP-12 - Design and iteratively develop programs that combine control structures, including nested loops and compound conditionals.
  • 3A-AP-16 - Design and iteratively develop computational artifacts for practical intent, personal expression, or to address a societal issue by using events to initiate instructions.
  • 3B-AP-14 - Construct solutions to problems using student-created components, such as procedures, modules and/or objects.