Skip to the content

String methods

JavaScript · Unit 6: Strings

Strings come with methods: they go after a dot and always take parentheses.

toUpperCase() makes it uppercase, toLowerCase() lowercase and trim() removes the spaces at the edges.

const name = "ann";
console.log(name.toUpperCase());
console.log("  hi  ".trim() + "!");

Prints

ANN
hi!

The rest of the explanation is in the lesson, which is part of the full plan.

Exercises in this lesson

You do them in the app, which checks them on the spot and explains why.

  1. 1. Predict the output

    What does this code print?

  2. 2. Complete the code

    The person typed their name with extra spaces. Complete it to clean it up.

  3. 3. Predict the output

    What does this code print?

  4. 4. Multiple choice

    What does "hello".indexOf("z") return?

  5. 5. Predict the output

    What does this code print?

  6. 6. Predict the output

    What does this code print?

  7. 7. Complete the code

    Complete it to delete every dash in the phone.

  8. 8. Find the bug

    This program should print the email in lowercase, max@mail.com. Which line has the error?

  9. 9. Put the lines in order

    Order the function that accepts "yes" even if the person types it with capitals or extra spaces.

  10. 10. Find the case that fails

    domain(email) should return whatever comes after the @, or an empty string "" if the email has no @. Which call breaks it?

Do this lesson

It opens in your browser. This lesson is part of the full plan; the first unit of each course is free.

See all lessons →