--- id: bd7123c9c448eddfaeb5bdef title: Find the Length of a String challengeType: 1 videoUrl: '' localeTitle: 找到字符串的长度 --- ## Description
您可以通过在字符串变量或字符串文字后面写.length来查找String值的长度。 "Alan Peter".length; // 10例如,如果我们创建了一个变量var firstName = "Charles" ,我们可以通过使用firstName.length属性找出字符串"Charles"长度。
## Instructions
使用.length属性计算lastName变量中的字符数,并将其分配给lastNameLength
## Tests
```yml tests: - text: lastNameLength应该等于8。 testString: 'assert((function(){if(typeof lastNameLength !== "undefined" && typeof lastNameLength === "number" && lastNameLength === 8){return true;}else{return false;}})(), "lastNameLength should be equal to eight.");' - text: 您应该使用.length来获取lastName的长度,如下所示: lastName.length 。 testString: 'assert((function(){if(code.match(/\.length/gi) && code.match(/\.length/gi).length >= 2 && code.match(/var lastNameLength \= 0;/gi) && code.match(/var lastNameLength \= 0;/gi).length >= 1){return true;}else{return false;}})(), "You should be getting the length of lastName by using .length like this: lastName.length.");' ```
## Challenge Seed
```js // Example var firstNameLength = 0; var firstName = "Ada"; firstNameLength = firstName.length; // Setup var lastNameLength = 0; var lastName = "Lovelace"; // Only change code below this line. lastNameLength = lastName; ```
### After Test
```js console.info('after the test'); ```
## Solution
```js // solution required ```