110 likes | 128 Views
Explore different types of numbers in JavaScript, from integers to floating points and scientific notations. Learn basic math operations, type conversions, and common functions for working with numbers.
E N D
Stephen Delaney sdelaney@skokielibrary.info • JavaScript Basics
Review: Working With Numbers • Doing math in JavaScript • The random challenge
Types of Numbers Integers • 10, -8, 2787382 Floating point numbers • 3.14, -10.6454 Scientific notation • 5.7e+4 => 57000
Is this a number? var greatNumber = ‘10’ *Introducing typeOf()
What are these for? • += • -= • *= • /= var score = 10 score += 7 17
What’s the difference between? • parseInt() • parseInt(10.6) 10 • parseFloat() • parseFloat(10.6) 10.6
What do these mean? • NaN • Not a Number • DRY • Don’t Repeat Yourself
What do these do? Math.round() • Math.round(10.6) 11 Math.floor() • Math.floor(10.6) 10 Math.ceil() • Math.ceil(10.6) 11
What does this do? Math.random() • Floating number, from 0 (inclusive) to 1 (exclusive)
Challenge: Write the code to generate a random number between 1 and 10. Math.floor(Math.random() * 10) + 1