If you're seeing this message, it means we're having trouble loading external resources on our website.

If you're behind a web filter, please make sure that the domains *.kastatic.org and *.kasandbox.org are unblocked.

Main content

Challenge: Input validation

Instructions

Step 1

Validate the month

Amy’s site has a web form for collecting a user’s birthday, but she notices that some site visitors entered nonsense month numbers like 0 or 47. She wants to add input validation to her form, so she can display an informative error message if a user enters an impossible date.

Amy added validation for the day, but now wants to handle the month input.

  • Wrap the month error in a conditional so that it only prints if the month is invalid.

Valid month values must be between 1 and 12, where 1 represents January and 12 represents December. If the month is between 1 and 12, inclusive, the month error should not print.

Do not change the wording of the error messages.

Code editor

Code files

Output