{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

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

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

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

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

View Full Document Right 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)
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)
Image of page 3

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

View Full Document Right Arrow Icon
Math Object Examples Round.html Round2.html MathEg.html
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
Image of page 5

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

View Full Document Right 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 
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  indexOf:Returns the first occurrence of character x 
Image of page 7

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

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

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern