Updated 07/18/14 |
|
In my first demonstration I will use the charAt() method. This method will return the character at the location within the () for the charAt() method. For this example I will create a variable to use as a parameter for the charAt() method. This is what I call my backwards script, it uses the name variable to store the data I want to display backwards. Then I create a variable ("v") that will use the name variables length property to display the last character using the charAt() method. Finally I will subtract decrement variable v until there is no more characters left. Below is the script: <script type="text/javascript"> And here is the output: Now lets try manipulating another string with the link() method. This method will return a string as a hyperlink. Below is the script: <script type="text/javascript">
You can always check out any of the other string data manipulation methods and use them in a similar manner. We will try one more here to give you one more example, then you can try creating your own JavaScript and manipulate a string using a string object method. For this example we will use the toUpperCase() method. This string be converted to all upper case letters when used with this method. I also use another string method fontcolor to change the font of the testString variable to red. Here is an example of the code: <script type="text/javascript"> // toLowerCase() method would do the opposite, convert the case of
the entire string to lower case. This script produces the following string: Or you can get the same results by concatenating the 2 statements into one: testString = testString.toUpperCase().fontcolor("red") Now lets try formatting a string with the Italics(), fontcolor() and Big() methods.
// Using Italics() and Big() method to convert the string Produces the following string: Now try formatting string and using string object methods in your own JavaScript!
|
This site was last updated 07/08/14