You can find out how many characters there are in a string by using the length
property of a string:
var name = "Daniel";
var nameLength = name.length;
console.log(nameLength); // Logs 6
You can also get a modified version of a string by calling string methods. Let's try one:
var name = "Daniel";
var nameLowerCase = name.toLowerCase();
console.log(nameLowerCase); // "daniel"
You can find out more about string properties and methods by searching for "JavaScript string methods".
- Log a message that includes the length of your name
My name is Daniel and my name is 6 characters long
- Log the same message using the variable,
name
provided - Use the
.trim
method to remove the extra whitespace
My name is Daniel and my name is 6 characters long