Logic: Validating User Input
Summary
Materials
- Day 6 PowerPoint deck
- Validating User Input handout
- Validating User Input handout in Word
- [winnerWinner] (for teacher)
- [helloFriend] (for teacher)
- Activity: User Input and String Logic
Additional references:
- Learn about the history of the Oregon Trail game
- Classic Oregon Trail game
Instructional Activities and Classroom Assessments
- Logical Expressions Refresher (10 minutes)
- User Interaction (10 minutes)
- Activity: Logical Expressions and User Input (30 minutes)
- Reflection/Homework
Learning Objectives
- AAP-1.A Represent a value with a variable.β3.A
- AAP-2.D Evaluate expressions that manipulate strings.β4.B
- AAP-2.E For relationships between two variables, expressions, or values:
- a. Write expressions using relational operators.β2.B
- b. Evaluate expressions that use relational operators.β 4.B
- AAP-2.F For relationships between Boolean values: a. Write expressions using logical operators.β2.B b. Evaluate expressions that use logic operators.β4.B
- AAP-2.H For selection:
- a. Write conditional statements.β2.B
- b. Determine the result of conditional statements.β 4.B
- CRD-2.C Identify input(s) to a program
Essential Knowledge
AAP-1.A.1 A variable is an abstraction inside a program that can hold a value. Each variable has associated data storage that represents one value at a time, but that value can be a list or other collection that in turn contains multiple values.
AAP-2.D.1 String concatenation joins together two or more strings end-to-end to make a new string.
AAP-2.E.1 A Boolean value is either true or false.
AAP-2.E.2 The exam reference sheet provides the following relational operators: =, β , >, <, β₯, and β€. Text and Block:
Β§ a = b
Β§ a β b
Β§ a > b
Β§ a < b
Β§ a β₯ b
Β§ a β€ b
These are used to test the relationship between two variables, expressions, or values. A comparison using a relational operator evaluates to a Boolean value. For example, a = b evaluates to true if a and b are equal; otherwise, it evaluates to false.AAP-2.F.2 The exam reference sheet provides Text: NOT condition Block: NOT condition which evaluates to true if condition is false; otherwise it evaluates to false.
AAP-2.F.5 The operand for a logical operator is either a Boolean expression or a single Boolean value.
AAP-2.H.1 Conditional statements, or βif-statements,β affect the sequential flow of control by executing different statements based on the value of a Boolean expression.
AAP-2.H.2 The exam reference sheet provides
- Text: IF(condition) { <block of statements> }
- Block: IF condition block of statements in which the code in block of statements is executed if the Boolean expression condition evaluates to true; no action is taken if condition evaluates to false.
CRD-2.C.1 Program inputs are data sent to a computer for processing by a program. Input can come in a variety of forms, such as tactile, audio, visual, or text.
CRD-2.C.4 Inputs usually affect the output produced by a program.
CRD-2.C.6 Input can come from a user or other programs.
Details
1. Logical expressions refresher (15 minutes)
- Define Logical Expressions.
- Explain how you can use Logical Expressions.
- Define logical operators and Boolean algebra.
- Demonstrate how to use Boolean equations and expressions.
2. User interaction (10 minutes)
- Direct students to recreate code segments that incorporate user input.
- Students will use the ask block in a logic statement to test built in Boolean values.
- Students will then use the ask for string block to see how a pre-made function calls an on-screen keyboard.
- Discuss alternating Booleans.
3. Activity: User input and string logic (25 minutes)
- Direct students to go to Validating User Input of the page.
- Task students with completing Task 1, Task 2, and Task 2 Challenge.
- If students have time, encourage them to recreate code segments in JavaScript.
4. Reflection/Homework
If you run out of time, you may also assign this as individual homework. Students should complete their reflection.
- In task #2, you implemented a basic βpassword checker.β What is one possible downside of the way that the code was implemented?
- List at least two ways in which user input could be used in writing a text based game.
5. Extension activities
- For students who finish early, encourage them to complete the problem set at Problem Set: User Input.
- Practice sets are written as JavaScript exercises and can be accomplished using block based code. Students can choose whichever code editor they feel most comfortable with to complete the problems. If needed, students can copy the JavaScript snippet from the problem set, paste it into the JavaScript workspace in MakeCode, then switch back to Block. It has been demonstrated that exposing students to both block and text based code simultaneously makes the transition from block to text more successful.