Goal: In the string and number methods lesson, we learned:
- Methods are a type of function. Not all functions are methods.
- Methods always belong to a specific data type.
- We call methods on a receiver.
- Methods can be chained
- You can use the
+ operator on strings in place of the
- You can call methods on variables that represent strings or numbers
Now that we've covered methods, strings, and numbers independently, practice common methods meant specifically for strings and numbers by completing the exercises listed below.
- What is a receiver for a method?
- What is the difference between a function and a method?
- What is a return value? What does it represent?
- What does 'chaining' methods mean? What does that look like?
- Name one string method.
- Name one number method.
- Name two ways to combine multiple strings together.
Complete both of the prompts below.
String Methods Practice
Practice calling methods on strings:
- Concatenate the following strings together:
- Uppercase the following string:
"hey there friend!"
- Uppercase just the
"hey" and then concatenate it to
Number Methods Practice
Practice calling methods on numbers:
- Set a variable equal to a number.
- Call a method on that variable that turns the number into a string.
- Set a new variable equal to
- Call a method on the new variable that limits the number of decimals to
3 so that the result is