1.7 KiB
1.7 KiB
id, title, challengeType, videoUrl, localeTitle
id | title | challengeType | videoUrl | localeTitle |
---|---|---|---|---|
bd7123c9c451eddfaeb5bdef | Use Bracket Notation to Find the Last Character in a String | 1 | 使用括号表示法查找字符串中的最后一个字符 |
Description
var firstName = "Charles"
,则可以使用firstName[firstName.length - 1]
获取字符串最后一个字母的值。 Instructions
lastName
变量中的最后一个字符。 暗示 如果卡住了,请尝试查看
lastLetterOfFirstName
变量声明。 Tests
tests:
- text: <code>lastLetterOfLastName</code>应为“e”。
testString: 'assert(lastLetterOfLastName === "e", "<code>lastLetterOfLastName</code> should be "e".");'
- text: 你必须使用<code>.length</code>来获取最后一个字母。
testString: 'assert(code.match(/\.length/g).length === 2, "You have to use <code>.length</code> to get the last letter.");'
Challenge Seed
// 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
console.info('after the test');
Solution
// solution required