Advertisement
Guest User

Untitled

a guest
Mar 26th, 2017
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.75 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta name="description" content="string-manipulation">
  5. <meta charset="utf-8">
  6. <meta name="viewport" content="width=device-width">
  7. <title>JS Bin</title>
  8. </head>
  9. <body>
  10.  
  11. <script id="jsbin-javascript">
  12. /* 1. String Manipulation:
  13. * Let's look at some simple ways to manipulate strings! We can add them together,
  14. * Make them all caps or all lowercase, we can access individual characters just
  15. * like in an array, and much more!
  16. */
  17.  
  18. //Concatenation is where you add two strings together. See below.
  19. var greeting = "Sup";
  20. var homie = " yo!";
  21.  
  22. console.log(greeting + homie); //Logs "Sup yo!".
  23.  
  24. //toUpperCase makes all letters capital or uppercase as some say.
  25. var size = "I'm very small";
  26.  
  27. console.log(size.toUpperCase()); //Prints our string in all caps.
  28.  
  29. //toLowerCase makes it...lowercase...makes sense.
  30. var height = "I'M VERY TALL";
  31.  
  32. console.log(height.toLowerCase()); //Prints out our string in lowercase.
  33.  
  34. //Let's pick out one letter from a string.
  35.  
  36. var poppins = "supercalifragilisticexpialidocious";
  37. console.log(poppins[6]);
  38. /*Prints "a" the seventh letter in our string. Strings can be accessed like arrays,
  39. * so they too are zero indexed, meaning the count across their elements begins
  40. *with zero.
  41. */
  42.  
  43. //Splitting separates strings, based on a given criteria which it removes.
  44. var fruit = "Banana";
  45.  
  46. (console.log(fruit.split("n", fruit.length))); //Prints ["Ba", "a", "a"].
  47.  
  48. console.log(fruit[2].toUpperCase());// returns "N".
  49. </script>
  50.  
  51.  
  52.  
  53. <script id="jsbin-source-javascript" type="text/javascript">/* 1. String Manipulation:
  54. * Let's look at some simple ways to manipulate strings! We can add them together,
  55. * Make them all caps or all lowercase, we can access individual characters just
  56. * like in an array, and much more!
  57. */
  58.  
  59. //Concatenation is where you add two strings together. See below.
  60. var greeting = "Sup";
  61. var homie = " yo!";
  62.  
  63. console.log(greeting + homie); //Logs "Sup yo!".
  64.  
  65. //toUpperCase makes all letters capital or uppercase as some say.
  66. var size = "I'm very small";
  67.  
  68. console.log(size.toUpperCase()); //Prints our string in all caps.
  69.  
  70. //toLowerCase makes it...lowercase...makes sense.
  71. var height = "I'M VERY TALL";
  72.  
  73. console.log(height.toLowerCase()); //Prints out our string in lowercase.
  74.  
  75. //Let's pick out one letter from a string.
  76.  
  77. var poppins = "supercalifragilisticexpialidocious";
  78. console.log(poppins[6]);
  79. /*Prints "a" the seventh letter in our string. Strings can be accessed like arrays,
  80. * so they too are zero indexed, meaning the count across their elements begins
  81. *with zero.
  82. */
  83.  
  84. //Splitting separates strings, based on a given criteria which it removes.
  85. var fruit = "Banana";
  86.  
  87. (console.log(fruit.split("n", fruit.length))); //Prints ["Ba", "a", "a"].
  88.  
  89. console.log(fruit[2].toUpperCase());// returns "N".
  90.  
  91.  
  92. </script></body>
  93. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement