Find the Length of a String
You can find the length of a String
value by writing .length
after the string variable or string literal.
console.log("Alan Peter".length);
The value 10
would be displayed in the console. Note that the space character between "Alan" and "Peter" is also counted.
For example, if we created a variable const firstName = "Ada"
, we could find out how long the string Ada
is by using the firstName.length
property.
Use the .length
property to set lastNameLength
to the number of characters in lastName
.
Tests
- Waiting: 1. You should not change the variable declarations in the
// Setup
section. - Waiting: 2.
lastNameLength
should be equal to eight. - Waiting: 3. You should be getting the length of
lastName
by using.length
like this:lastName.length
.
/** * Your test output will go here */