Lesson 13: Other Forms of Input

Overview

In this lesson students continue to explore ways to use conditional statements to take user input. In addition to the simple keyDown() command learned yesterday, students will learn about several other keyboard input commands as well as ways to take mouse input.

Purpose

Students have learned how to make simple decisions with conditionals. Sometimes however we want to make decision based on if the condition we asked about originally was false or we want to make a decision based on multiple conditions being true. Thats where else statements and more complex conditionals come in. Else statements are a second statement which is attached to a if statement. Else statements execute when the if statement it is attached to is false. You can think of it as "if something is true do thing 1 else do thing 2.

This concept is introduced alongside several new key and mouse input commands, allowing students to gradually build up programs that input in different ways.

Assessment Opportunities

  1. Use an if-else statement to control the flow of a program.

    See Level 5 in Code Studio.

  2. Respond to a variety of types of user input.

    Use the wrap up discussion to check students' understanding of the different types of user input. You may also informally check their ability to use them as they progress through the Code Studio lesson.

Agenda

View on Code Studio

Objectives

Students will be able to:

  • Use an if-else statement to control the flow of a program.
  • Respond to a variety of types of user input.

Vocabulary

  • Conditionals - Statements that only run when certain conditions are true.

Introduced Code

Teaching Guide

Warm Up (5 minutes)

Check for Understanding

Remarks

Today we'll be picking up today where we left off yesterday - using conditionals to write programs that respond to user input. Let's refresh what we learned yesterday.

Prompt:

  • What is a Boolean? (eg. a true/false value)
  • What is the relationship between a Boolean and a Conditional? (eg. a conditional asks a Boolean question and runs code if the answer is true)
  • What are some examples of comparison operators that result in a Boolean? (eg. >, <, ==)
  • What is the difference between = and ==? (eg. = is used to assign a value, == is used to check if two values are equal)

Remarks

That's great! Today we're going to look at a wayto make our conditionals even more powerful, and see some new ways to get user input.

Activity (40 minutes)

If/Else and More Input

Transition: Move the class to Code Studio, and have students complete the prediction level as a class or in small groups, then talk about what they found.

Video: Watch the video as a class and review the discussion questions together.

Code Studio levels

View on Code Studio

Discussion Goals

Make sure students are thinking of situations in which they want two different things to happen, depending on the situation. For example, they may say that they want one animation if the sprite is moving to the left and a different animation if the sprite is moving to the right. Challenge the students to think about when they would just use an if block, and when an ifelse block is necessary.

  • Input with If-Else
  • (click tabs to see student view)

Wrap Up (5 minutes)

Wrap Up

Assessment Opportunity

This discussion serves as a brief review and assessment of the new user input commands. As students share out, press them to explain why their choice is better than other, similar choices (mouseDown / mouseWentDown / mouseWentUp). If any commands are missing after all the groups have shared out, elicit the missing ones from the group before moving on.

Prompt: You now have many different ways to detect user input. With a partner, choose three difference user input commands and think of an example of when you might use them. Be ready to share with the class!

Standards Alignment

View full course alignment

CSTA K-12 Computer Science Standards (2017)

AP - Algorithms & Programming
  • 2-AP-11 - Create clearly named variables that represent different data types and perform operations on their values.
  • 2-AP-12 - Design and iteratively develop programs that combine control structures, including nested loops and compound conditionals.
  • 2-AP-13 - Decompose problems and subproblems into parts to facilitate the design, implementation, and review of programs.
  • 2-AP-16 - Incorporate existing code, media, and libraries into original programs, and give attribution.
  • 2-AP-17 - Systematically test and refine programs using a range of test cases.
  • 2-AP-19 - Document programs in order to make them easier to follow, test, and debug.