--- id: bd7123c9c451eddfaeb5bdef title: Use Bracket Notation to Find the Last Character in a String challengeType: 1 videoUrl: '' localeTitle: 使用括号表示法查找字符串中的最后一个字符 --- ## Description
为了获得字符串的最后一个字母,您可以从字符串的长度中减去一个字母。例如,如果var firstName = "Charles" ,则可以使用firstName[firstName.length - 1]获取字符串最后一个字母的值。
## Instructions
使用括号表示法查找lastName变量中的最后一个字符。 暗示
如果卡住了,请尝试查看lastLetterOfFirstName变量声明。
## Tests
```yml tests: - text: lastLetterOfLastName应为“e”。 testString: assert(lastLetterOfLastName === "e"); - text: 你必须使用.length来获取最后一个字母。 testString: assert(code.match(/\.length/g).length === 2); ```
## Challenge Seed
```js // Example var firstName = "Ada"; var lastLetterOfFirstName = firstName[firstName.length - 1]; // Setup var lastName = "Lovelace"; // Only change code below this line. var lastLetterOfLastName = lastName; ```
### After Test
```js console.info('after the test'); ```
## Solution
```js // solution required ```