2018-10-10 18:03:03 -04:00
---
id: bd7123c9c448eddfaeb5bdef
2021-02-06 04:42:36 +00:00
title: Find the Length of a String
2018-10-10 18:03:03 -04:00
challengeType: 1
2020-04-29 18:29:13 +08:00
videoUrl: 'https://scrimba.com/c/cvmqEAd'
forumTopicId: 18182
2021-01-13 03:31:00 +01:00
dashedName: find-the-length-of-a-string
2018-10-10 18:03:03 -04:00
---
2020-12-16 00:37:30 -07:00
# --description--
2018-10-10 18:03:03 -04:00
2021-02-06 04:42:36 +00:00
You can find the length of a `String` value by writing `.length` after the string variable or string literal.
2018-10-10 18:03:03 -04:00
2020-12-16 00:37:30 -07:00
`"Alan Peter".length; // 10`
2018-10-10 18:03:03 -04:00
2021-02-06 04:42:36 +00:00
For example, if we created a variable `var firstName = "Charles"` , we could find out how long the string `"Charles"` is by using the `firstName.length` property.
2018-10-10 18:03:03 -04:00
2020-12-16 00:37:30 -07:00
# --instructions--
2018-10-10 18:03:03 -04:00
2021-02-06 04:42:36 +00:00
Use the `.length` property to count the number of characters in the `lastName` variable and assign it to `lastNameLength` .
2018-10-10 18:03:03 -04:00
2020-12-16 00:37:30 -07:00
# --hints--
2018-10-10 18:03:03 -04:00
2021-02-06 04:42:36 +00:00
You should not change the variable declarations in the `// Setup` section.
2018-10-10 18:03:03 -04:00
```js
2020-12-16 00:37:30 -07:00
assert(
code.match(/var lastNameLength = 0;/) & &
code.match(/var lastName = "Lovelace";/)
);
2018-10-10 18:03:03 -04:00
```
2021-02-06 04:42:36 +00:00
`lastNameLength` should be equal to eight.
2018-10-10 18:03:03 -04:00
2020-12-16 00:37:30 -07:00
```js
assert(typeof lastNameLength !== 'undefined' & & lastNameLength === 8);
```
2018-10-10 18:03:03 -04:00
2021-02-06 04:42:36 +00:00
You should be getting the length of `lastName` by using `.length` like this: `lastName.length` .
2020-04-29 18:29:13 +08:00
2018-10-10 18:03:03 -04:00
```js
2020-12-16 00:37:30 -07:00
assert(code.match(/=\s*lastName\.length/g) && !code.match(/lastName\s*=\s*8/));
2018-10-10 18:03:03 -04:00
```
2020-04-29 18:29:13 +08:00
2021-01-13 03:31:00 +01:00
# --seed--
## --seed-contents--
```js
// Setup
var lastNameLength = 0;
var lastName = "Lovelace";
// Only change code below this line
lastNameLength = lastName;
```
2020-12-16 00:37:30 -07:00
# --solutions--
2021-01-13 03:31:00 +01:00
```js
var lastNameLength = 0;
var lastName = "Lovelace";
lastNameLength = lastName.length;
```