Advertisement
Guest User

slothico

a guest
Oct 24th, 2014
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.64 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset=“utf-8”>
  5. <title> Assignment 2 </title>
  6. </head>
  7.  
  8. <body>
  9. <script type="text/javascript">
  10. <!--
  11. text = "now is the time for all good people to come to the aid of their country";
  12. document.write("Text: "+text+"<br><br>");
  13.  
  14. // Each Letter Capitalized
  15. function capitalize(str) {
  16. return str.replace(/\w\S*/g, function(txt) {
  17. return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase(); });
  18. }
  19. x = capitalize(text);
  20. document.write(x+"<br>");
  21.  
  22. // Each Last Letter Capitalized
  23. function capitalize2(str) {
  24. return str.replace(/\w\S*/g, function(txt) {
  25. return txt.substr(0,txt.length-1).toLowerCase() + txt.substr(txt.length-1).toUpperCase(); });
  26. }
  27.  
  28. x = capitalize2(text);
  29. document.write(x+"<br>");
  30.  
  31. // Capitalize Letters Without UpperCase
  32. for(i=0;i<text.length;i++)
  33. {
  34. if ( text.charCodeAt(i) == 32) {
  35. document.write(" ");
  36. }
  37. else {
  38. a = String.fromCharCode(text.charCodeAt(i)-32)
  39. document.write(a);
  40. }
  41. }
  42.  
  43. document.write("<br>");
  44.  
  45.  
  46. // first i
  47. index1 = text.indexOf("i");
  48. document.write(+index1+ "th poisition holds the first 'i' <br>");
  49.  
  50. // last i
  51. index2 = text.lastIndexOf("i");
  52. document.write(+index2+ "th poisition holds the last 'i' <br>");
  53.  
  54. // How many letters
  55. letter1 = text.charAt(8);
  56. document.write("8th letter is '"+letter1+"'<br>");
  57.  
  58. // Length
  59. lenght1 = text.length;
  60. document.write("There are "+lenght1+" letters in the text<br>");
  61.  
  62.  
  63.  
  64.  
  65. <!--
  66. </script>
  67. </body>
  68. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement