Presentation is loading. Please wait.

Presentation is loading. Please wait.

Checking If User Input Is Numeric.  Quiz  Detecting numeric input  Finish Prior Lecture  Y'all work on one of the problems listed 2.

Similar presentations


Presentation on theme: "Checking If User Input Is Numeric.  Quiz  Detecting numeric input  Finish Prior Lecture  Y'all work on one of the problems listed 2."— Presentation transcript:

1 Checking If User Input Is Numeric

2  Quiz  Detecting numeric input  Finish Prior Lecture  Y'all work on one of the problems listed 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: loose_typing.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  Once you've got that done, pick problems from exercise #2 to do 6


Download ppt "Checking If User Input Is Numeric.  Quiz  Detecting numeric input  Finish Prior Lecture  Y'all work on one of the problems listed 2."

Similar presentations


Ads by Google