Presentation is loading. Please wait.

Presentation is loading. Please wait.

Conditional Statements.  Checking if input is a number  Radio buttons  Check boxes 2.

Similar presentations


Presentation on theme: "Conditional Statements.  Checking if input is a number  Radio buttons  Check boxes 2."— Presentation transcript:

1 Conditional Statements

2  Checking if input is a number  Radio buttons  Check boxes 2

3 3 Checking if a value is a number

4  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

5  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

6  Do exercise #1 for this topic 6

7 7 HTML Radio buttons

8  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

9  http://www.webmonkey.com/2010/02/javascript_debugging_for_beginners/ http://www.webmonkey.com/2010/02/javascript_debugging_for_beginners/  Keep the console open  Assertions  Using alert  Using console.log  Printing out objects (including fields)  http://stackoverflow.com/questions/988363/how-can-i-debug-my-javascript-code http://stackoverflow.com/questions/988363/how-can-i-debug-my-javascript-code  Using an actual debugger – debugger;  Console.log( " object: %o string: %s", obj, obj.property); 9


Download ppt "Conditional Statements.  Checking if input is a number  Radio buttons  Check boxes 2."

Similar presentations


Ads by Google