Presentation is loading. Please wait.

Presentation is loading. Please wait.

© 2007 D. J. ForemanJS-m1 String, Math & Miscellaneous Methods & Properties.

Similar presentations


Presentation on theme: "© 2007 D. J. ForemanJS-m1 String, Math & Miscellaneous Methods & Properties."— Presentation transcript:

1 © 2007 D. J. ForemanJS-m1 String, Math & Miscellaneous Methods & Properties

2 © 2007 D. J. Foreman JS-m2 String Object Methods & Properties anchor( ) big( ) blink( ) bold( ) charAt( ) fontcolor( ) fontsize( ) indexOf( ) italics( ) lastIndexOf( ) link( ) small( ) sub( ) sup( ) substr(start, length) substring(start, end) toLowerCase( ) toUpperCase( ) length is a property of a string - so, no ( )

3 © 2007 D. J. Foreman JS-m3 Example: indexOf Purpose: locate a string in another string Let x be a string variable (maybe from some kind of input operation) that currently has the value: "DJ Foreman" We want to see if it contains an "F" J = x.indexOf("F"); J now has the position of the "F" Remember that we start counting at ZERO So J now has the value of 3

4 © 2007 D. J. Foreman JS-m4 Example: lastindexOf, length X="DJ Foreman, Ph. D."; document.write(X.lastIndexOf(" ")+" "); document.write(X.length); Result is:15 17

5 © 2007 D. J. Foreman JS-m5 Example of substr Purpose: copy a piece of a string, given its start and length Let X be a string variable (maybe from some kind of input operation) that currently has the value: "DJ Foreman, Ph. D." If we want the "Foreman": M=X.indexOf(" ")+1;// finds the 1 st char after the blank N=X.indexOf(",");// finds the comma L=N-M;// computes the length Y=X.substr(M, L);// gets the "Foreman" into Y

6 © 2007 D. J. Foreman JS-m6 Example of substring Purpose: copy a piece of a string, given its start and ending position Let X be a string variable (maybe from some kind of input operation) that currently has the value: "DJ Foreman, Ph. D." If we want the "Foreman": M=X.indexOf(" ")+1;// finds the 1 st char after the blank N=X.indexOf(",");// finds the comma Y=X.substring(M,N);// gets the "Foreman" into Y

7 © 2007 D. J. Foreman JS-m7 Some Math Object Methods abs( ) ceil( ), floor( ) exp( ) log( ) max( ), min( ) pow( ) random( ) round( ) sqrt( ) sin(radians), asin( ) cos( ), acos( ) tan( ), atan( )

8 © 2007 D. J. Foreman JS-m8 Some Math Object Properties E LN2, LN10 LN2E, LOG2E PI SQRT2 SQRT1_2 (sqrt of 1/2) ex: Math.PI These are all constants

9 © 2007 D. J. Foreman JS-m9 Some Misc Methods blur( ) focus( ) select( ) eval( ) to re-call the interpreter parseInt( ) or ParseFloat( ) if var x="10"; y="5"; x+y gives "105" parseInt(x)+parseInt(y) gives 15

10 © 2007 D. J. Foreman JS-m10 Some Useful References "Javascript by Example" (various publishers, if you can find it) "How to Set Up and Maintain a WWW Site", Addison Wesley "Essential Javascript for Web Professionals", Prentice Hall "Essential CSS & DHTML for Web Professionals", Prentice Hall


Download ppt "© 2007 D. J. ForemanJS-m1 String, Math & Miscellaneous Methods & Properties."

Similar presentations


Ads by Google