Lesson 12: Conditionals and User Input
Following the introduction to booleans and if statements in the previous lesson, students are introduced to a new block called
keyDown() which returns a boolean and can be used in conditionals statements to move sprites around the screen. By the end of this lesson students will have written programs that take keyboard input from the user to control sprites on the screen.
One common way conditionals are used is to check for different types of user input especially key presses. Having a way for a user to interact with a program makes it more interesting and dynamic. Without interaction from the user it is very difficult to create a game. Therefore the introduction of conditionals and user inputs for decision making is the first big step toward creating games.
Students will be able to:
- Use conditionals to react to keyboard input
- Move sprites in response to keyboard input
Warm Up (5 min)
The goal here isn’t to get into the technical specifics of how programs can take input (students will get to that in the online portion of the lesson), but rather to get students thinking about how allow user input could change the programs they’ve made. Encourage students to think back to Unit 1 and the various computer inputs and outputs they explored then. Which inputs would be most useful for the types of programs they’ve been making?
Discuss: So far all of the programs you’ve written run without any input from the user. How might adding user interaction make your programs more useful, effective, or entertaining? How might a user provide input into your program?
Activity (40 min)
Transition: Send students to Code Studio
Code Studio levels
- Lesson Overview
- Keyboard Input
- Editing Images
- Keyboard Input
Wrap Up (5 min)
Prompt: To get students to continue thinking about how conditionals can be used in programming, prompt them to come up with scenarios in games or programs they use regularly that might be triggered by conditionals.
Discuss: Have students share responses. Student responses might include:
- If my username and password are correct, log me into Facebook
- If Pacman has collected all the balls, start the next level
- If my keyboard or mouse hasn’t moved in 10 minutes, turn on the screensaver
TRY THE LESSON 12 CHALLENGES