Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ---------------------------------------------------------------------------------------------------------------------------------
- <html>
- <head>
- <title>substring()</title>
- <script src="substring.js"></script>
- </head>
- <body>
- </body>
- </html>
- ---------------------------------------------------------------------------------------------------------------------------------
- /* SUBSTRING VARIABLES */
- var number1 = "yellow brick";
- var number2 = "terminator";
- var number3 = "elephante";
- var number4 = "mary poppin’s umbrella";
- var number5 = "alligator";
- var number6 = "donkey teeth";
- var number7 = "my big red hat";
- var number8 = "supercalifragilisticexpialidocious";
- var number9 = "small orange robot";
- var number10 = "ten fifteen";
- /* PRINT STATEMENTS */
- /* 1. Get the 3rd character up and including to the 10th letter “yellow brick”, which would be "llow bri" */
- document.write("substring() #1 <br>".bold());
- document.write("Get the 3rd character up and including to the 10th letter “yellow brick”, which would be \"llow bri\" ");
- document.write("<br>");
- document.write("Output: ".bold() + number1.substring(2, 10));
- document.write("<br>");
- document.write("The correct code was: \"number1.substring(2, 10)\"");
- document.write("<br><br>");
- /* 2. Get the 5th letter up to the 7th letter of “terminator”, which would be "in" */
- document.write("substring() #2 <br>".bold());
- document.write("Get the 5th letter up to the 7th letter of “terminator”, which would be \"in\" ");
- document.write("<br>");
- document.write("Output: ".bold() + number2.substring(4, 6));
- document.write("<br>");
- document.write("The correct code was: \"number2.substring(4, 6)\"");
- document.write("<br><br>");
- /* 3. Get the 1st letter only of “elephante”, which would be "e" */
- document.write("substring() #3 <br>".bold());
- document.write("Get the 1st letter only of “elephante”, which would be \"e\" ");
- document.write("<br>");
- document.write("Output: ".bold() + number3.substring(0, 1));
- document.write("<br>");
- document.write("The correct code was: \"number3.substring(0, 1)\"");
- document.write("<br><br>");
- /* 4. Get the apostrophe of “mary poppin’s umbrella”, which would be "'" */
- document.write("substring() #4 <br>".bold());
- document.write("Get the apostrophe of “mary poppin’s umbrella”, which would be \"'\" ");
- document.write("<br>");
- document.write("Output: ".bold() + number4.substring(11, 12));
- document.write("<br>");
- document.write("The correct code was: \"number4.substring(11, 12)\"");
- document.write("<br><br>");
- /* 5. Get the last letter of “alligator”, which would be "r" */
- document.write("substring() #5 <br>".bold());
- document.write("Get the last letter of “alligator”, which would be \"r\" ");
- document.write("<br>");
- document.write("Output: ".bold() + number5.substring(8));
- document.write("<br>");
- document.write("The correct code was: \"number5.substring(8)\"");
- document.write("<br><br>");
- /* 6. Get the second word of the String “donkey teeth”, which would be "teeth" */
- document.write("substring() #6 <br>".bold());
- document.write("Get the second word of the String “donkey teeth”, which would be \"teeth\" ");
- document.write("<br>");
- document.write("Output: ".bold() + number6.substring(7));
- document.write("<br>");
- document.write("The correct code was: \"number6.substring(7)\"");
- document.write("<br><br>");
- /* 7. Get the 5th character up and including the 12th of “my big red hat”, which would be "ig red h" */
- document.write("substring() #7 <br>".bold());
- document.write("Get the 5th character up and including the 12th of “my big red hat”, which would be \"ig red h\" ");
- document.write("<br>");
- document.write("Output: ".bold() + number7.substring(4, 12));
- document.write("<br>");
- document.write("The correct code was: \"number7.substring(4, 12)\"");
- document.write("<br><br>");
- /* 8. Get the 18th letter of “supercalifragilisticexpialidocious”, which would be "t" */
- document.write("substring() #8 <br>".bold());
- document.write("Get the 18th letter of “supercalifragilisticexpialidocious”, which would be \"t\" ");
- document.write("<br>");
- document.write("Output: ".bold() + number8.substring(17, 18));
- document.write("<br>");
- document.write("The correct code was: \"number8.substring(17, 18)\"");
- document.write("<br><br>");
- /* 9. Get the 5th letter up and including the 8th of “small orange robot”, which would be "l" */
- document.write("substring() #9 <br>".bold());
- document.write("Get the 5th letter up and including the 8th of “small orange robot”, which would be \"l\" ");
- document.write("<br>");
- document.write("Output: ".bold() + number9.substring(4, 5));
- document.write("<br>");
- document.write("The correct code was: \"number9.substring(4, 5)\"");
- document.write("<br><br>");
- /* 10. Get the 2nd letter up to the 6th in “ten fifteen”, which would be "e" */
- document.write("substring() #10 <br>".bold());
- document.write("Get the 2nd letter up to the 6th in “ten fifteen”, which would be \"e\" ");
- document.write("<br>");
- document.write("Output: ".bold() + number10.substring(1, 2));
- document.write("<br>");
- document.write("The correct code was: \"number10.substring(1, 2)\"");
- document.write("<br><br>");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement