1 / 8

JavaScript

Pertemuan 10. JavaScript. String Object. Return the length of a string Style String The index of() method The match() method Replace Characters in string – replace(). Return the length of a string. <html> <body> <script type="text/javascript"> var txt="Hello World!";

tamah
Download Presentation

JavaScript

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Pertemuan 10 JavaScript

  2. String Object • Return the length of a string • Style String • The index of() method • The match() method • Replace Characters in string – replace()

  3. Return the length of a string <html> <body> <script type="text/javascript"> var txt="Hello World!"; document.write(txt.length); </script> </body> </html> 12

  4. Style String Big: Hello World! Small: Hello World! Bold: Hello World! Italic: Hello World! Blink: Hello World! (does not work in IE) Fixed: Hello World! Strike: Hello World! Fontcolor: Hello World! Fontsize: Hello World! Lowercase: hello world! Uppercase: HELLO WORLD! Subscript: Hello World! Superscript: Hello World! Link: Hello World! <html> <body> <script type="text/javascript"> var txt="Hello World!"; document.write("<p>Big: " + txt.big() + "</p>"); document.write("<p>Small: " + txt.small() + "</p>"); document.write("<p>Bold: " + txt.bold() + "</p>"); document.write("<p>Italic: " + txt.italics() + "</p>"); document.write("<p>Blink: " + txt.blink() + " (does not work in IE)</p>"); document.write("<p>Fixed: " + txt.fixed() + "</p>"); document.write("<p>Strike: " + txt.strike() + "</p>"); document.write("<p>Fontcolor: " + txt.fontcolor("Red") + "</p>"); document.write("<p>Fontsize: " + txt.fontsize(16) + "</p>"); document.write("<p>Lowercase: " + txt.toLowerCase() + "</p>"); document.write("<p>Uppercase: " + txt.toUpperCase() + "</p>"); document.write("<p>Subscript: " + txt.sub() + "</p>"); document.write("<p>Superscript: " + txt.sup() + "</p>"); document.write("<p>Link: " + txt.link("http://www.w3schools.com") + "</p>"); </script> </body> </html>

  5. The index of() method <html> <body> <script type="text/javascript"> var str="Hello world!"; document.write(str.indexOf("Hello") + "<br />"); document.write(str.indexOf("World") + "<br />"); document.write(str.indexOf("world")); </script> </body> </html> 0-16

  6. The match() method <html> <body> <script type="text/javascript"> var str="Hello world!"; document.write(str.match("world") + "<br />"); document.write(str.match("World") + "<br />"); document.write(str.match("worlld") + "<br />"); document.write(str.match("world!")); </script> </body> </html> worldnullnullworld!

  7. Replace Characters in string – replace() <html> <body> <script type="text/javascript"> var str="Visit Microsoft!"; document.write(str.replace(/Microsoft/,"W3Schools")); </script> </body> </html> Visit W3Schools!

  8. Tugas

More Related