Advertisement
476179

7C-EX1PatteringInStrings

Nov 16th, 2018
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.12 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8">
  5. <title>The For Loop</title>
  6. </head>
  7.  
  8. <body>
  9. <script>
  10.  
  11.  
  12. // ex1 find length of string
  13. var phraseOne = "this is a simple phrase.";
  14. document.write("\"this simple phrase\" is "+ phraseOne.length + " chraracters long<br>");
  15. // backslash beofore means just to read as a character
  16. // the length method returns number of characters in a string
  17.  
  18. //ex 2 converts strings to up uppercase
  19. var phraseTwo = "hello world!";
  20. document.write(phraseTwo.toUpperCase()+ "<br>");
  21.  
  22. //se3 converts to lowercase
  23. var str1 ="hello";
  24. var str2 ="Hello";
  25. if (str1.toLowerCase() == str2.toLowerCase() )
  26. {
  27. document.write("yes, they are the same<br>")
  28. }
  29. else
  30. {
  31. document.write("no they are NOT the same")
  32. }
  33.  
  34. // ex4 finding characters in a string
  35. var phraseThree = "strings are cool";
  36. var position = phraseThree.charAt(2)
  37. document.write(position);
  38. // first position is actualy zero so S=0 T=1 R=2 I=3 N=4 G=5
  39. </script>
  40. </body>
  41. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement