This is geared toward beginners and anyone looking to refresh their knowledge.
See the Previous Level Here
Level 6 will cover:
- Use Bracket Notation to Find the Nth Character in a String
- Use Bracket Notation to Find the Last Character in a String
- Use Bracket Notation to Find the Nth-to-Last Character in a String
If we want to find which character of a string is sitting at a particular value, we again use bracket notation with the number position we want to find [Nth].
let player = "Druid"; console.log(player); "u"
When we want to find the last character of a string, we can subtract one from the string's length.
let spell = "Fireball"; spell[spell.length - 1]; "l"
Just as we did before to find the Nth and the last character in a string, we can combine the two to find the last to Nth character.
let enemy = "Goblin Mage"; let secondToLastLetter = enemy[enemy.length - 2]; console.log(secondToLastLetter); "g"