Advertisement
Crenox

JavaScript substring() School Project (Advanced Java)

Apr 14th, 2016
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.22 KB | None | 0 0
  1. ---------------------------------------------------------------------------------------------------------------------------------
  2. <html>
  3. <head>
  4. <title>substring()</title>
  5. <script src="substring.js"></script>
  6. </head>
  7.  
  8. <body>
  9. </body>
  10. </html>
  11. ---------------------------------------------------------------------------------------------------------------------------------
  12. /* SUBSTRING VARIABLES */
  13. var number1 = "yellow brick";
  14.  
  15. var number2 = "terminator";
  16.  
  17. var number3 = "elephante";
  18.  
  19. var number4 = "mary poppin’s umbrella";
  20.  
  21. var number5 = "alligator";
  22.  
  23. var number6 = "donkey teeth";
  24.  
  25. var number7 = "my big red hat";
  26.  
  27. var number8 = "supercalifragilisticexpialidocious";
  28.  
  29. var number9 = "small orange robot";
  30.  
  31. var number10 = "ten fifteen";
  32.  
  33. /* PRINT STATEMENTS */
  34. /* 1. Get the 3rd character up and including to the 10th letter “yellow brick”, which would be "llow bri" */
  35. document.write("substring() #1 <br>".bold());
  36. document.write("Get the 3rd character up and including to the 10th letter “yellow brick”, which would be \"llow bri\" ");
  37. document.write("<br>");
  38. document.write("Output: ".bold() + number1.substring(2, 10));
  39. document.write("<br>");
  40. document.write("The correct code was: \"number1.substring(2, 10)\"");
  41. document.write("<br><br>");
  42.  
  43. /* 2. Get the 5th letter up to the 7th letter of “terminator”, which would be "in" */
  44. document.write("substring() #2 <br>".bold());
  45. document.write("Get the 5th letter up to the 7th letter of “terminator”, which would be \"in\" ");
  46. document.write("<br>");
  47. document.write("Output: ".bold() + number2.substring(4, 6));
  48. document.write("<br>");
  49. document.write("The correct code was: \"number2.substring(4, 6)\"");
  50. document.write("<br><br>");
  51.  
  52. /* 3. Get the 1st letter only of “elephante”, which would be "e" */
  53. document.write("substring() #3 <br>".bold());
  54. document.write("Get the 1st letter only of “elephante”, which would be \"e\" ");
  55. document.write("<br>");
  56. document.write("Output: ".bold() + number3.substring(0, 1));
  57. document.write("<br>");
  58. document.write("The correct code was: \"number3.substring(0, 1)\"");
  59. document.write("<br><br>");
  60.  
  61. /* 4. Get the apostrophe of “mary poppin’s umbrella”, which would be "'" */
  62. document.write("substring() #4 <br>".bold());
  63. document.write("Get the apostrophe of “mary poppin’s umbrella”, which would be \"'\" ");
  64. document.write("<br>");
  65. document.write("Output: ".bold() + number4.substring(11, 12));
  66. document.write("<br>");
  67. document.write("The correct code was: \"number4.substring(11, 12)\"");
  68. document.write("<br><br>");
  69.  
  70. /* 5. Get the last letter of “alligator”, which would be "r" */
  71. document.write("substring() #5 <br>".bold());
  72. document.write("Get the last letter of “alligator”, which would be \"r\" ");
  73. document.write("<br>");
  74. document.write("Output: ".bold() + number5.substring(8));
  75. document.write("<br>");
  76. document.write("The correct code was: \"number5.substring(8)\"");
  77. document.write("<br><br>");
  78.  
  79. /* 6. Get the second word of the String “donkey teeth”, which would be "teeth" */
  80. document.write("substring() #6 <br>".bold());
  81. document.write("Get the second word of the String “donkey teeth”, which would be \"teeth\" ");
  82. document.write("<br>");
  83. document.write("Output: ".bold() + number6.substring(7));
  84. document.write("<br>");
  85. document.write("The correct code was: \"number6.substring(7)\"");
  86. document.write("<br><br>");
  87.  
  88. /* 7. Get the 5th character up and including the 12th of “my big red hat”, which would be "ig red h" */
  89. document.write("substring() #7 <br>".bold());
  90. document.write("Get the 5th character up and including the 12th of “my big red hat”, which would be \"ig red h\" ");
  91. document.write("<br>");
  92. document.write("Output: ".bold() + number7.substring(4, 12));
  93. document.write("<br>");
  94. document.write("The correct code was: \"number7.substring(4, 12)\"");
  95. document.write("<br><br>");
  96.  
  97. /* 8. Get the 18th letter of “supercalifragilisticexpialidocious”, which would be "t" */
  98. document.write("substring() #8 <br>".bold());
  99. document.write("Get the 18th letter of “supercalifragilisticexpialidocious”, which would be \"t\" ");
  100. document.write("<br>");
  101. document.write("Output: ".bold() + number8.substring(17, 18));
  102. document.write("<br>");
  103. document.write("The correct code was: \"number8.substring(17, 18)\"");
  104. document.write("<br><br>");
  105.  
  106. /* 9. Get the 5th letter up and including the 8th of “small orange robot”, which would be "l" */
  107. document.write("substring() #9 <br>".bold());
  108. document.write("Get the 5th letter up and including the 8th of “small orange robot”, which would be \"l\" ");
  109. document.write("<br>");
  110. document.write("Output: ".bold() + number9.substring(4, 5));
  111. document.write("<br>");
  112. document.write("The correct code was: \"number9.substring(4, 5)\"");
  113. document.write("<br><br>");
  114.  
  115. /* 10. Get the 2nd letter up to the 6th in “ten fifteen”, which would be "e" */
  116. document.write("substring() #10 <br>".bold());
  117. document.write("Get the 2nd letter up to the 6th in “ten fifteen”, which would be \"e\" ");
  118. document.write("<br>");
  119. document.write("Output: ".bold() + number10.substring(1, 2));
  120. document.write("<br>");
  121. document.write("The correct code was: \"number10.substring(1, 2)\"");
  122. document.write("<br><br>");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement