Professional Documents
Culture Documents
Explore
Unit 6 Lesson 1 - Warm Up
Prompt:
myName
Unit 6 Lesson 1 - Activity
But what if we have a lot of information?
Do This:
With a partner, discuss the challenges that you’d encounter if
you need to store 10, or 100, or 1,000 pieces of information
using variables.
Unit 6 Lesson 1 - Activity
Do This:
Lists Make a list like the one
● Gallon baggie connected to smaller baggies below that holds
● Each smaller baggie can hold one value
● Gallon baggies are named with the same rules as a between 2 and 4 values.
variable (no spaces, can’t start with number) Share it with another
● Smaller baggies are numbered starting at 0 group.
LunchFo
od
0 1 2
element element element
Unit 6 Lesson 1 - Activity
Your list is made up of elements. Each element has its own index.
Indexes start at 0 and count up. The length of the list is how many
elements it contains. This list has 3 elements and indexes from 0 to
2.
Unit 6 Lesson 1 - Activity
0 1
Unit 5 Lesson 1 - Activity
myList[1] Do
This:
● This expression “accesses” the value at thatand
What do lunchFood[0]
lunchFood[2] access?
index of the list.
● Also uses square brackets Compare your answers
with another group.
LunchFo
od
0 1 2
Unit 5 Lesson 1 - Activity
myNumbers[0] +
0 1 2 myNumbers[2]
evaluates 35
10 accesses
25 to
Do This: Write three expression that include + to the list
you created. Use the examples above for inspiration
Trade with another group and have them evaluate your
expressions
Unit 5 Lesson 1 - Activity
myList[1] = “hello”
Assigns the value on the right to the index
Just like variable assignment, the old value is thrown away and
replaced.
myNumbers
myNumbers
01 myNumbers[0] = 5;
0 1 2
Do This:
Run this program. Compare your result with another
group.
1 varmyStuff = [20, “hat”, “pow”,
5];
2 myStuff[1] = “cat”;
3 myStuff[2] = myStuff[1];
4 myStuff[0] = myStuff[3] + 10;
5 myStuff[3] = myStuff[0] +
myStuff[0];
myStuff
0 1 2 3
Unit 5 Lesson 1 - Activity
Do This:
You can use expressions in the place of the list index.
Run this program and compare your result with another
group.
1 varmyStuff = [“dog”,”cat”,3,10];
2 myStuff[2-1] = “tree”;
3 myStuff[myStuff[2]] = myStuff[0];
myStuff
0 1 2 3
Unit 5 Lesson 1 - Activity
removeItem(list, index)
Removes the element in the given list at the given
index All items to the right are shifted over
The last index is removed from the list myNumbers
01 removeItem(myNumbers,1);
0 1
myNumbers
02 removeItem(myNumbers,0);
0
Do This: Discuss what the list will
contain after line 02 runs.
Unit 5 Lesson 1 - Activity
appendItem(list, item)
Adds an element to the end of the list
A new index is added to the list to create a place for the
element The new item is placed in this new indexmyNumbers
myNumbers
01 appendItem(myNumbers,50);
0 1
02 appendItem(myNumbers,100); myNumbers
nums
01 insertItem(nums,1,20);
0 1 2
02 insertItem(nums,1,100); nums
Command Reference
Doprogram.
Run this This:Compare your result removeItem(list, index)
appendItem(list, item)
with another group. insertItem(list, index, item)
What is the length of the list at the end?
00 var aList = [20,
01 appendItem(aList,
“hat”, “pow”]; 5);
02 appendItem(aList, 10);
03 removeItem(aList, 1);
04 insertItem(aList, 2, “bang”);
aList
0 1 3 4
2
Unit 5 Lesson 1 - Activity
Do This:
Command Reference
Run this program. Compare your result
removeItem(list, index)
with another group. appendItem(list, item)
What is the length of the list at the end? insertItem(list, index, item)
00 var bList = [“to”, 5,
“po”];
01 appendItem(bList, bList[2] + + bList[0]);
“ta”
02 insertItem(bList, 2-1, “go”);
03 removeItem(bList, 2);
bLis
t
0 1 3
2
Unit 6 Lesson 1 - Wrap Up
Unit 6 Lesson 1 - Wrap Up
Unit 6 Lesson 1 - Wrap Up
favNums
Key Takeaways
● A List is an ordered collection of 22
0 1 2
elements
● An Element is an individual value in a list that is
assigned a unique index var favNums = [74, 53, 22];