Conditional Statements
Checking if input is a number Radio buttons Check boxes 2
3 Checking if a value is a number
Examples of data types: Integer - whole numbers only, but positive, negative, and zero are allowed Floating-point / real - any number (whole or with a decimal point), positive, negative, zero Strings – text ("a string of individual characters") Boolean – true or false JS will try to convert from one to another in order to help you out. FILE: loosely_typed.html Note: multiplying by two is great Adding 4 isn't great Sometimes we need to tell it what to do 4
The isNaN() function will tell us if it's NOT a number NaN = Not A Number parseFloat() will then convert it to a real, floating-point number with decimals Use parseInt() if you want to drop anything after the decimal point Then it's safe to do math on it FILE: checking_for_numbers.html Step 1: Check if it's actually a number using isNaN (error & exit if it isn't) Step 2: Convert it to a number using parseFloat/parseInt Step 3: Do the math 5
Do exercise #1 for this topic 6
7 HTML Radio buttons
If Form validation If not a number, etc? HTML If…else 2-item radio buttons? HTML Multiway An item in a list is best described as ____________ Day or week Grade (small scale) Default case is an error N-way radio button HTML Drop-down list HTML Logical ops Guessing game? Figuring out tax in a variety of states, for a variety of items? 8
Keep the console open Assertions Using alert Using console.log Printing out objects (including fields) Using an actual debugger – debugger; Console.log( " object: %o string: %s", obj, obj.property); 9