Skip to main content
Version: v1.1

✏️ 1.2.0.15 Practice: String and Number Methods

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.
  • There are built-in JavaScript methods for strings and numbers
  • Methods can be chained
  • You can use the + operator on strings in place of the concat method
  • 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.

Warm Up


  • 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 is an argument? How do you provide one to a method in JavaScript?
  • 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.

Code


Complete both of the prompts below.

String Methods Practice

Practice calling methods on strings:

  • Concatenate the following strings together:
    • "hi" and "there"
    • "hey", "there", and "friend!
  • Uppercase the following string: "hey there friend!"
  • Uppercase just the "hey" and then concatenate it to "there" and "friend!"

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 3.14159265359.
  • Call a method on the new variable that limits the number of decimals to 3 so that the result is 3.141.