Presentation is loading. Please wait.

Presentation is loading. Please wait.

Using Built In Objects Kevin Harville.

Similar presentations


Presentation on theme: "Using Built In Objects Kevin Harville."— Presentation transcript:

1 Using Built In Objects Kevin Harville

2 Date() instantiation options:
birthday = new Date(); //returns now birthday = new Date("June 20, :00:00"); birthday = new Date(6, 20, 2001); birthday = new Date(6, 20, 2001, 8, 0, 0); Source: Sams Teach Yourself JavaScript in 24 Hours.

3 Setting a Date object myDay.setDate(4); myDay.setMonth(0);
myDay.setYear(99); //use setFullYear myDay.setFullYear(1999); myDay.setHours(23); myDay.setMinutes(30); myDay.setSeconds(0);

4 Getting Date Object Info
alert(myDay.getDate()); document.write(myDay.getMonth()); myYear = myDay.getYear(); //use getFullYear myDay.getFullYear(); myDay.getHours(); myDay.getMinutes(); myDay.getSeconds();

5 Math Math is encapsulated in an object format.
There are things Math can do - methods, and properties of math, such as PI. Math properties never change Therefore, a function such as raising a number to a power is done via a Math method: myVar = Math.pow ( 2, 4 ); Don't make your own math object. Use the object, Math, javascript provides.

6 Math Methods Math.random()
returns a random number from zero up to, but not including, one.

7 Math Methods - Rounding
Math.round( myVar ) Math.floor( myVar ) Math.ceil( myVar )

8 Math Methods - Trigonometry
Math.acos(x) Math.asin(x) Math.atan(x) Math.cos(x) Math.sin(x) Math.tan(x) IMPORTANT - THESE CALCULATIONS ARE DONE IN RADIANS. A SIMPLE BUT NECESSARY CONVERSION FROM RADIANS TO DEGREES NEEDED.

9 Math Minimum / Maximum Math.max ( valA, valB ) Math.min ( valA, valB)

10 Math Powers and Roots Math.pow ( num, pwr ) Math.sqrt ( 25 )

11 Other Math Methods Other Math methods exist. Consult your reference materials when doing higher math.

12 Math Properties Math.E Math.PI Math.LN2 Math.LN10 Math.LOG2E
Math.SQRT1_2 Math.SQRT2 The Math object's properties are Math constants. The only Math property I want you to know for this class is Math.PI

13 Browser Objects

14 Document Object Model window location document history anchors [ ]
links [ ] forms [ ] images [ ] elements [ ]

15 Things you can do with DOM
Refer to document properties Clear a document Refer to and modify specific anchors and links. Move to and refer to previous and next pages. Move to a specific new page

16 Things you can do... You can do much more.
The details in this chapter were only briefly covered. Read Chapters 9 and 10. All this is done by using the Document Object Model and object-oriented programming.


Download ppt "Using Built In Objects Kevin Harville."

Similar presentations


Ads by Google