CPNT 262 Day 7 - Validating value types, Scope and Review
Housekeeping
- Assignment 1 now due Sunday Oct 17 @ 11:59pm
- Assignment 2 announced
Trophy of the day
1. Spoiler demo: Tip calculator upgrade
2. Value validation
A common task in untyped languages is confirming the value type that you're working with.
Materials
- Takeaways: Validating values
Activity
- Using your knowledge of comparison operators and conditional statements, add validation to your Tip Calculator that ensures that:
- Remove the
required
attribute fromtotal
field so we can test; - The user entered a number for Bill Total (i.e. not empty);
- The entered Bill Total is greater than $0;
- Throw an error if
total
is negative or missing.
- Remove the
3. Scope
Materials
4. Activity: Text area counter
Materials
Activity
Lab Time
- Walkthrough of this week's in-class code
Prep
Validating value types
- Takeaways: Validating values
Scope
- Article: A Simple Explanation of Scope in JavaScript
- Video: Javascript the Weird Parts: Function scope and the execution stack @59:58 (you can stop at Dynamic Typing)
- StackOverflow: Do DOM tree elements with ids become global variables?