Day 3 - Obje (contd.) cts Day 3 Javascript Math Object

Info iconThis preview shows pages 1–8. Sign up to view the full content.

View Full Document Right Arrow Icon
Objects (contd. .) Day 3
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Javascript Math Object The built-in Math object includes mathematical constants and  functions. You do not need to create the Math object before  using it. To store a random number between 0 and 1 in a variable called  "r_number": r_number=Math.random() To store the rounded number of 8.6 in a variable called  "r_number": r_number=Math.round(8.6)
Background image of page 2
Math Object Methods Methods are invoked by lines like "Math.sin(1)". abs(a) - Returns the absolute value of a. The result value is 23 in the example below. resultval = Math.abs(-23) acos(a) - Returns the angle in radians that has a cosine of the passed value. The value of "resultval" is 90 degrees. resultval = (180/Math.PI) * Math.cos(0) asin(a) - Returns the angle in radians that has a sine of the passed value. The value of "resultval" is 90 degrees. resultval = (180/Math.PI) * Math.sin(1) atan(a) - Returns the angle in radians that has a tangent of the passed value. The "resultval" will be almost 90 degrees. resultval = (180/Math.PI) * Math.atan(100)
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Math Object Examples Round.html Round2.html MathEg.html
Background image of page 4
Javascript String Object Various ways of Declaring String Object var myString = new String(); myString = "This is a string"; var myString = new String ("This is a string"); var myString = "This is a string"; Example: String.html
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
String Properties and Methods Properties: Length : length of the string Methods: Anchor:Creates a named anchor (hypertext target) big :Sets text to big  Blink:Sets text to blinking  bold :Sets text to bold 
Background image of page 6
charAt:Returns the character at a specified position  fixed :Sets text in fixed-pitch font  fontcolor :Sets the font color  fontsize :Sets font size 
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 8
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 26

Day 3 - Obje (contd.) cts Day 3 Javascript Math Object

This preview shows document pages 1 - 8. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online