Goal: In the string methods lesson, we learned:
- Methods can be called on strings
- Methods can be chained
- You can use the
+ operator on strings in place of the
Now that we've covered both methods and strings independently, practice common methods meant specifically for strings by completing the exercises listed below.
- What does 'chaining' a method mean? What does that look like?
- Name two string methods.
- Name two ways to combine multiple strings together.
String Methods Practice
Practice calling methods on strings:
- Set a variable equal to a string
- Call a method on that variable.
- Set another variable with a string in all uppercase.
- Use the
concat() method with your two variables.
- Now concatenate them with the shortcut.
- Use the
toUpperCase() method on your first variable.
- Now use the
toLowerCase() method on your second variable.
- Find the character at the 3rd position of either of your variables.
- Check out the MDN's documentation of string methods and try out at least five new methods for yourself. If some of them don't make sense, don't worry about it - just try the ones that do. (Stick to the section labelled Methods unrelated to HTML. Click on the method itself to see how to use it in your code.)