Validating User Input
Activity
Go to Activity: User Input and String Logic. Complete student tasks 1, 2 and 2 challenge.
Tasks
Task 1
- Start with winnerWinner code.
- Add an else branch - use splash to say “Bye”.
- Add an else if statement which provides an “option for failure.” Use an ask that asks “Do you want to lose?”
- Make sure the player only gets the “You lost!” message if they respond “OK” to the prompt from “Do you want to lose?”
- Comment your code.
Task 2
- Start with code from helloFriend.
- Create a new variable called input.
- Set input to ask for string with the prompt text “What is your password?”
- Create an if else block that compares the ‘password’ from user input with the string “Arcade”.
- If the user enters Arcade, splash “login successful”.
- Otherwise, splash “login failed”.
- Comment your code.
Task2 Challenge
- Use or to also compare your stored password with "***"
- 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
- 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 can be used in writing a text based game.