Skip to content

Class 03 (Strings & Arrays)

KJ Monahan edited this page May 14, 2024 · 1 revision

Class 3: Strings and Arrays

In the prep work for this lesson, the students learned:

  1. What strings and arrays represent and that strings are immutable.
  2. How to use bracket notation to:
    1. Index into a string or array.
    2. Update array elements.
  3. 6 common string methods and 13 common array methods.
  4. How to use template literals and how to include newlines (\n) and tabs (\t) in console.log output.
  5. How to create and access a multi-dimensional array.

Large Group Time (Instructor Notes)

Announcements

For Part-Time Students:

  1. Remind students of the due date for the first graded assignment
  2. Other items as needed...

For Full-Time Students:

  • Welcome to Day 3
  • Items as needed

Lesson 3 Topics That Require More Attention

  1. There are 2 open ended Check Your Understanding questions in the strings chapter. Spend time discussing each one:
    1. Given word = 'Rutabaga', why does word.length return the integer 8, but word[8] is undefined?
    2. Given pet = 'cat', why do the statements console.log(pet + 's'); and pet += 's'; NOT violate the immutability of strings?
  2. Zero-based indexing
  3. Live code examples for using split and join to convert between strings and arrays
  4. Students need more practice with the following related to template literals:
    1. Using back-ticks instead of quotes.
    2. Using ${} to insert variables.
  5. Emphasize the difference between what an array method returns vs. how that method affects the original array
  6. As time permits:
    1. Review method chaining.
    2. Discuss the quirks in how JavaScript sorts an array of numbers and how we work around this.
  7. Studio intro:
    1. The studio is a fairly straightforward application of string and array methods. Remind students that the appendices in the book are good for syntax reminders.
    2. This studio is also a great time to play around with the code. Encourage the students to ask themselves "What if I try..." after completing a particular step in the activity.

Studio (IA Notes)

  1. Part 2 of the studio, "Array and String Conversion", introduces students to working in code that contains unit tests.
    1. Instructions have been provided in the textbook and starter code. An appendix has also been created to help students work in starter code like this.
  2. Common student stumbling blocks:
    1. Recalling the proper syntax for the required string and array methods.
    2. Setting up template literals.
    3. Remembering to convert numerical user inputs from strings to numbers.
    4. Setting up an if / else statement to validate user input.
    5. Running the correct file in the terminal. (For studios with unit tests, like the graded assignment, they'll need to run a different file than the one they're editing. Learners may notice that none of the functions in array-testing.js are called in that file and have questions.)
  3. Deal with the issues above as they occur in your session - this is a good time for individual check-ins or rotating between groups.
  4. Encourage your students to play after they finish a particular task. Prepare some "What if..." or "What about trying..." questions for students who need a friendly prompt.
  5. After the array exercises, encourage your students to try to reduce the lines of code by implementing method chaining.
    1. Example: string.split(' ').reverse().join(', ').