1.7 KiB
1.7 KiB
id, title, challengeType, videoUrl, forumTopicId
id | title | challengeType | videoUrl | forumTopicId |
---|---|---|---|---|
bd7123c9c452eddfaeb5bdef | Use Bracket Notation to Find the Nth-to-Last Character in a String | 1 | https://scrimba.com/c/cw4vkh9 | 18344 |
Description
var firstName = "Charles"
string by using firstName[firstName.length - 3]
Example:
var firstName = "Charles";
var thirdToLastLetter = firstName[firstName.length - 3]; // thirdToLastLetter is "l"
Instructions
lastName
string.
Hint: Try looking at the example above if you get stuck.
Tests
tests:
- text: <code>secondToLastLetterOfLastName</code> should be "c".
testString: assert(secondToLastLetterOfLastName === 'c');
- text: You should use <code>.length</code> to get the second last letter.
testString: assert(code.match(/\.length/g).length > 0);
Challenge Seed
// Setup
var lastName = "Lovelace";
// Only change code below this line
var secondToLastLetterOfLastName = lastName; // Change this line
After Test
(function(v){return v;})(secondToLastLetterOfLastName);
Solution
var lastName = "Lovelace";
var secondToLastLetterOfLastName = lastName[lastName.length - 2];