1 of 12

Unit 5

List 3 Lists Practice

2 of 12

To do: December 13 - in your IN

  • Declare a variable named family and assign to it a list of the first names of your family members (immediate family) including yourself. What data type will you use?
  • Write code to print only your name referring to the variable name family.
  • Write code that adds to the end of the list the first name of a member of your extended family. How do you add the name to the end of the list?

3 of 12

What is a list in JavaScript? an array

In JavaScript, you can use an array to keep a list of elements. An array is a data structure in JavaScript used to represent a list.

4 of 12

Vocabulary Review

Unit 5 Lesson 3 - Warm Up

List -

Element -

Index -

an ordered collection of elements

an individual value in a list that is assigned a unique index

a common method for referencing the elements in a list or string using numbers

5 of 12

Using list.length-1 to access last item in array

myArray[myArray.length-1]

var myArray = [3, -4, 5, 0, 7];�var last = myArray[myArray.length-1];�console.log(last);

>>

6 of 12

Using list.length-1 to access last item in array

myArray[myArray.length-1]

var myArray = [3, -4, 5, 0, 7];�var last = myArray[myArray.length-1];�console.log(last);

>> 7

7 of 12

Go over homework

  • goFormative U5L01 Lists Explore, U5L02 Lists Investigate
  • Complete Khan Academy - Binary Review - articles/exercises

8 of 12

String commands

The characters in a string each have an index beginning with 0.

  • string.length returns the length of a string (number of characters)
  • string.substring(start,end) returns a portion of the string, beginning at the start index and ending with the character before the end index.

Example: �var city = "Houston";�console.log(city.length);�console.log(city.substring(3, 6);

H

o

u

s

t

o

n

0

1

2

3

4

5

6

char

index

9 of 12

String commands

The characters in a string each have an index beginning with 0.

  • string.length returns the length of a string (number of characters)
  • string.substring(start,end) returns a portion of the string, beginning at the start index and ending with the character before the end index.

Example: �var city = "Houston";�console.log(city.length); 7�console.log(city.substring(1, 4); "ous"

H

o

u

s

t

o

n

0

1

2

3

4

5

6

char

index

10 of 12

String commands

var name = "Debbie";

console.log(name.length);

console.log(name.substring(1,4));

console.log(name.substring(2,3));

console.log(name.substring(3,6));

console.log(name.substring(2,7));

11 of 12

Complete Code.org U5L03 bubbles 1-10 - pair programming

12 of 12

Homework

  • Complete Code.org U5L03 bubbles 1-10
  • goFormative - U5L03 Lists Practice