Close
Close full mode
logoMakeCode AP CSP

Validating User Input

Activity

Go to Activity: User Input and String Logic. Complete student tasks 1, 2 and 2 challenge.

Tasks

Task 1

  1. Start with winnerWinner code.
  2. Add an else branch - use splash to say “Bye”.
  3. Add an else if statement which provides an “option for failure.” Use an ask that asks “Do you want to lose?”
  4. Make sure the player only gets the “You lost!” message if they respond “OK” to the prompt from “Do you want to lose?”
  5. Comment your code.

Task 2

  1. Start with code from helloFriend.
  2. Create a new variable called input.
  3. Set input to ask for string with the prompt text “What is your password?”
  4. Create an if else block that compares the ‘password’ from user input with the string “Arcade”.
  5. If the user enters Arcade, splash “login successful”.
  6. Otherwise, splash “login failed”.
  7. Comment your code.

Task2 Challenge

  1. Use or to also compare your stored password with "***"
  2. Accept the password if the user’s input is equal to either "***" or "Arcade"

Extension

Use JavaScript or Pyhton to create a project.

Reflection/Homework

  1. In task #2, you implemented a basic "password checker." What is one possible downside of the way that the code was implemented?
  2. List at least two ways in which user input can be used in writing a text based game.
📘 Unit 5 - AAP Part 2 — Previous
Logic: Validating User Input
Next — 📘 Unit 5 - AAP Part 2
Student Tasks/Solutions