Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html>
- <head>
- <meta name="description" content="string-manipulation">
- <meta charset="utf-8">
- <meta name="viewport" content="width=device-width">
- <title>JS Bin</title>
- </head>
- <body>
- <script id="jsbin-javascript">
- /* 1. String Manipulation:
- * Let's look at some simple ways to manipulate strings! We can add them together,
- * Make them all caps or all lowercase, we can access individual characters just
- * like in an array, and much more!
- */
- //Concatenation is where you add two strings together. See below.
- var greeting = "Sup";
- var homie = " yo!";
- console.log(greeting + homie); //Logs "Sup yo!".
- //toUpperCase makes all letters capital or uppercase as some say.
- var size = "I'm very small";
- console.log(size.toUpperCase()); //Prints our string in all caps.
- //toLowerCase makes it...lowercase...makes sense.
- var height = "I'M VERY TALL";
- console.log(height.toLowerCase()); //Prints out our string in lowercase.
- //Let's pick out one letter from a string.
- var poppins = "supercalifragilisticexpialidocious";
- console.log(poppins[6]);
- /*Prints "a" the seventh letter in our string. Strings can be accessed like arrays,
- * so they too are zero indexed, meaning the count across their elements begins
- *with zero.
- */
- //Splitting separates strings, based on a given criteria which it removes.
- var fruit = "Banana";
- (console.log(fruit.split("n", fruit.length))); //Prints ["Ba", "a", "a"].
- console.log(fruit[2].toUpperCase());// returns "N".
- </script>
- <script id="jsbin-source-javascript" type="text/javascript">/* 1. String Manipulation:
- * Let's look at some simple ways to manipulate strings! We can add them together,
- * Make them all caps or all lowercase, we can access individual characters just
- * like in an array, and much more!
- */
- //Concatenation is where you add two strings together. See below.
- var greeting = "Sup";
- var homie = " yo!";
- console.log(greeting + homie); //Logs "Sup yo!".
- //toUpperCase makes all letters capital or uppercase as some say.
- var size = "I'm very small";
- console.log(size.toUpperCase()); //Prints our string in all caps.
- //toLowerCase makes it...lowercase...makes sense.
- var height = "I'M VERY TALL";
- console.log(height.toLowerCase()); //Prints out our string in lowercase.
- //Let's pick out one letter from a string.
- var poppins = "supercalifragilisticexpialidocious";
- console.log(poppins[6]);
- /*Prints "a" the seventh letter in our string. Strings can be accessed like arrays,
- * so they too are zero indexed, meaning the count across their elements begins
- *with zero.
- */
- //Splitting separates strings, based on a given criteria which it removes.
- var fruit = "Banana";
- (console.log(fruit.split("n", fruit.length))); //Prints ["Ba", "a", "a"].
- console.log(fruit[2].toUpperCase());// returns "N".
- </script></body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement