-
Notifications
You must be signed in to change notification settings - Fork 59
Class 03 (Strings & Arrays)
KJ Monahan edited this page May 14, 2024
·
1 revision
In the prep work for this lesson, the students learned:
- What strings and arrays represent and that strings are immutable.
- How to use bracket notation to:
- Index into a string or array.
- Update array elements.
- 6 common string methods and 13 common array methods.
- How to use template literals and how to include newlines (
\n
) and tabs (\t
) inconsole.log
output. - How to create and access a multi-dimensional array.
- Remind students of the due date for the first graded assignment
- Other items as needed...
- Welcome to Day 3
- Items as needed
- There are 2 open ended Check Your Understanding questions in the strings chapter. Spend time discussing each one:
- Given
word = 'Rutabaga'
, why doesword.length
return the integer 8, butword[8]
is undefined? - Given
pet = 'cat'
, why do the statementsconsole.log(pet + 's');
andpet += 's';
NOT violate the immutability of strings?
- Given
- Zero-based indexing
- Live code examples for using
split
andjoin
to convert between strings and arrays - Students need more practice with the following related to template literals:
- Using back-ticks instead of quotes.
- Using
${}
to insert variables.
- Emphasize the difference between what an array method returns vs. how that method affects the original array
- As time permits:
- Review method chaining.
- Discuss the quirks in how JavaScript sorts an array of numbers and how we work around this.
- Studio intro:
- 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.
- 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.
- Part 2 of the studio, "Array and String Conversion", introduces students to working in code that contains unit tests.
- 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.
- Common student stumbling blocks:
- Recalling the proper syntax for the required string and array methods.
- Setting up template literals.
- Remembering to convert numerical user inputs from strings to numbers.
- Setting up an
if / else
statement to validate user input. - 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.)
- Deal with the issues above as they occur in your session - this is a good time for individual check-ins or rotating between groups.
- 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.
- After the array exercises, encourage your students to try to reduce the lines of code by implementing method chaining.
- Example:
string.split(' ').reverse().join(', ')
.
- Example: