FreeCodeCamp.com - Basic JavaSript - Use Bracket Notation to Find the Nth Character in a String
Link to FreeCodeCamp
You can also use bracket notation to get the character at other positions within a string.
Remember that computers start counting at
0
, so the first character is actually the zeroth character.Instructions
Let's try to set
thirdLetterOfLastName
to equal the third letter of the lastName
variable using bracket notation.
Hint
Try looking at the
Try looking at the
secondLetterOfFirstName
variable declaration if you get stuck.
Sollution:
// Example
var firstName = "Ada";
var secondLetterOfFirstName = firstName[1];
// Setup
var lastName = "Lovelace";
// Only change code below this line.
var thirdLetterOfLastName = lastName[2];
Komentáře
Okomentovat