Font size
WorksheetsLIST
Total questions: 34
Worksheet time: 36mins
Jasmine is writing a shopping app. She has created a variable to keep track of the number of items in the shopping cart. Every time someone clicks the "addItemButton", she would like the variable to increase by 1.
What code should Jasmine insert where it says <missing code> in order for her app to work?
cart total = 1;
cartTotal + 1;
cartTotal = cartTotal +1;
var cartTotal = cartTotal + 1;
var cartTotal + 1;
Consider the following flow chart showing a process for program execution. Given that a = 5, and b = 10, what will be displayed by the program?
a is bigger
b
5
10
Nothing will be displayed
When creating lists, sometimes you will need to create a “scrolling pattern”.
Which of the following will not scroll beyond the end of a list?
if (index < myList.length-1) {
Index++
}
if (index > myList.length-1) {
Index++
}
if (index < myList.length) {
Index++
}
if (index > myList.length) {
Index++
}
What does the term 'Element' refer to in a list?
A) A unique identifier for each item
B) A method for looping through a list
C) An individual value in a list that is assigned a unique index
D) The process of naming a collection of data without referencing the details
If I want to place a new element anywhere in a list, I would use which of the following methods?
appendItem
insertItem
addItem
joinItem
myList = [5, 3, 12, 7, 19, 20, 23]. myList.length will return a value of ___
6
7
8
9
The first item in a list has an index of .....
0
1
2
3
Which of these is the correct code for creating a list of names?
nameList = John, Harry, Jesse, John, Harry, Harry
nameList = ("John", "Harry", "Jesse", "John", "Harry", "Harry")
nameList = ["John", "Harry", "Jesse", "John", "Harry", "Harry"]
nameList = [John, Harry, Jesse, John, Harry, Harry]
List items have an index number. In the following list, which item has the index number of 3?
["John", "Harry", "Jesse", "John", "Harry", "Harry"]
"John"
"Harry"
"Jesse"
What is the output of program below?
mariana_islands = ['Saipan', 'Tinian', 'Rota']
mariana_islands[0] = 'Guam'
print(mariana_islands)
['Saipan', 'Tinian', 'Rota']
['Guam', 'Tinian', 'Rota']
['Saipan', 'Tinian', 'Rota', 'Guam']
['Guam', 'Saipan', 'Tinian', 'Rota']
What is the output of program below?
mariana_islands = ['Guam', 'Saipan', 'Tinian', 'Rota']
print(mariana_islands[-1])
Guam
Saipan
Tinian
Rota
What will be displayed in the console when this program runs?
2
3
20
30
What will be displayed when this program finishes running?
3
6
7
5
What is wrong with the following attempt to initialize a list?
data = ["hockey", 4, False]
You should be using parentheses ( ) to surround the items in a list
Nothing, this will work correctly
The "=" sign
You cant have a list with different data types
Which vocabulary word is:
a common method for referencing the elements in a list or string using numbers
list
element
index
var numList = [10,20,30];
console.log ( numList [numList.length-1]);
What will be displayed in the console when this program runs?
2
3
20
30
Which vocabulary word is:
an ordered collection of elements
list
element
index
Which vocabulary word is:
an individual value in a list that is assigned a unique index
list
element
index
Match the index with the value.
var myNumbers = [32, 64, 33, 0, 15, 26, 3]
myNumbers[4]
64
15
0
32
//Consider this code:
var list = [10, 12, 14, 16, 18];
appendItem(list, 3);
insertItem(list, 2, 20);
removeItem(list, 0);
//What is printed to the console?
console.log(list);
10, 12, 14, 16, 18
10, 12, 14 , 20, 16, 18, 3
3, 12, 14, 20, 16, 18
12, 20, 14, 16, 18, 3
//Consider this code:
var list = [10, 12, 14, 16, 18];
appendItem(list, 3);
insertItem(list, 2, 20);
removeItem(list, 0);
//What is printed to the console?
console.log(list[0]);
(a)
//Consider this code:
var list = [10, 12, 14, 16, 18];
appendItem(list, 3);
insertItem(list, 2, 20);
removeItem(list, 0);
//What is printed to the console?
console.log(list.length);
(a)
//Consider this code:
var list = [10, 12, 14, 16, 18];
appendItem(list, 3);
insertItem(list, 2, 20);
removeItem(list, 0);
//What is printed to the console?
console.log(list[list.length-1]);
(a)
//Consider this code.
var beginning = "My name is ";
var end = "Mrs. Anderson";
var sentence = beginning + end;
//What is printed to the console?
console.log(sentence.length);
name
name is
y name
23
n
4
7
9
10
ab
A sequence of several variables, grouped together under a single name.
sequence
list
length
element
What is the name of this list?
Foodlunch
lunchfood
LunchFood
lunchFood
Refers to the number of elements that a list can hold.
[list].length
[list].length-1
What is this a picture and example of?
[list].length
[list].length-1
What is this a picture and example of?
Random Access List Pattern
Scrolling List Pattern
var list = [10, 12, 14, 16, 18];
removeItem(list, 0);
console.log(list[0]);
12
14
16
0
//Consider this code:
var list = [10, 12, 14, 16, 18];
//What is printed to the console?
console.log(list[list.length-1]);
10
16
18
14
What does this code do? names[0]="Chenda";
replaces an item in the list at index 0
adds an item or items to the END of a list
adds an item at a SPECIFIC INDEX in the list
deletes an item from the list.
wordList is a list of words that currently contains the values ["tree", "rock", "air"] Which of the following lines will result in the list containing the values ["air", "rock", "air"] ?
wordList[0] = wordList[2]
wordList[2] = wordList[0]
insertItem(wordList, 0, "air")
removeItem(wordList,0)
