String Indexing and Length, online

Six activities your students do on their own devices. See who's finished, and their scores.

String Indexing and Length in one minute

What students need to know

Since indexing starts at 0, index 1 is the second character. length is accessed directly as a property, not called as a method.

Strings are indexed starting at 0, just like arrays. length counts every character in the string, including spaces.

Mistakes students make

  • Use square brackets [], not round brackets, to access a character.
  • Missing the opening square bracket before the index.
  • Missing the closing square bracket after the index.
  • 'length' is misspelled as 'lenght'.
PREVIOUS · MODULE 28Arrays – reduce()
YOU ARE HERE · MODULE 29String Indexing and Length
NEXT · MODULE 30String Methods

Discover other journeys with this module

What students will learn in this module

Every question in Module 29

Quick questions

  1. Does word[0] access the first character of a string?AYesBNo
  2. Does .length give the number of characters in a string?AYesBNo
  3. Is () used instead of [] to access a character?AYesBNo
  4. Does .length need parentheses after it, like .length()?AYesBNo
  5. Is 'Length' with a capital L valid JavaScript syntax?ANoBYes

Key terms

Students type the meaning of:

  • length

Match the pairs

word[0]Match it to what it does
word.lengthMatch it to what it does
Accesses the second character of a stringMatch it to what it does
A property that never needs parenthesesMatch it to what it does
console.log(word(0));Match it to what it does
console.log(word.length());Match it to what it does

Fill in the blanks

  1. console.log(word_0]);

    Hint: Type the symbol that opens an index access.

  2. console.log(word.______);

    Hint: Type the property that gives a string's number of characters.

  3. let ch = word[_];

    Hint: Type the index of the second character.

  4. let name = "Amy";
    console.log(name.______);

    Hint: Type the property that gives a string's number of characters.

  5. let size = name.______;

    Hint: Type the property that gives a string's number of characters.

Spot the error

Question 1

Aconsole.log(word(0));Blet word = "cat";Cconsole.log(word.length);

Question 2

Alet text = "dog";Bconsole.log(text(1));Cconsole.log(text.length);

Question 3

Alet text = "cat";Bconsole.log(text.length);Cconsole.log(text0]);

Question 4

Alet word = "sun";Bconsole.log(word[0]);Cconsole.log(word.length);Dconsole.log(word[1);

Question 5

Alet name = "Amy";Bconsole.log(name[0]);Cconsole.log(name[1]);Dconsole.log(name[2]);Econsole.log(name.lenght);