Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="utf-8">
- <title>The For Loop</title>
- </head>
- <body>
- <script>
- // ex1 find length of string
- var phraseOne = "this is a simple phrase.";
- document.write("\"this simple phrase\" is "+ phraseOne.length + " chraracters long<br>");
- // backslash beofore means just to read as a character
- // the length method returns number of characters in a string
- //ex 2 converts strings to up uppercase
- var phraseTwo = "hello world!";
- document.write(phraseTwo.toUpperCase()+ "<br>");
- //se3 converts to lowercase
- var str1 ="hello";
- var str2 ="Hello";
- if (str1.toLowerCase() == str2.toLowerCase() )
- {
- document.write("yes, they are the same<br>")
- }
- else
- {
- document.write("no they are NOT the same")
- }
- // ex4 finding characters in a string
- var phraseThree = "strings are cool";
- var position = phraseThree.charAt(2)
- document.write(position);
- // first position is actualy zero so S=0 T=1 R=2 I=3 N=4 G=5
- </script>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement