String methods
JavaScript · Unit 6: Strings
- Full plan
- JavaScript
- 10 exercises
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. Predict the output
What does this code print?
2. Complete the code
The person typed their name with extra spaces. Complete it to clean it up.
3. Predict the output
What does this code print?
4. Multiple choice
What does
"hello".indexOf("z")return?5. Predict the output
What does this code print?
6. Predict the output
What does this code print?
7. Complete the code
Complete it to delete every dash in the phone.
8. Find the bug
This program should print the email in lowercase, max@mail.com. Which line has the error?
9. Put the lines in order
Order the function that accepts "yes" even if the person types it with capitals or extra spaces.
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?
It opens in your browser. This lesson is part of the full plan; the first unit of each course is free.