Tracking Multiple Items with Arrays Flashcards

1
Q

The script.js file contains an array called guestList. It contains a list of names. Add two new names to the end of the list using the array method you learned in the previous video.

var guestList = [‘Sandra’, ‘Omar’, ‘Magnus’, ‘Becky’];

Now, add 3 names to the beginning of the list using the other array method you learned in the last video.

A

guestList.push(“Name”, “Name”);
guestList.unshift(“Name”, “Name”, “Name”);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What array method adds an item to the end of an array?

A

push()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Complete the code below to store the number of items in the array scores into the variable totalScores:

var scores = [76, 79, 85, 87, 89 , 90, 99];

var totalScores = scores._____ ;

A

length

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What array method returns the first item from an array and removes it from the array?

A

shift()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Finish the code below to add the value 23 to the beginning of the array ages:

ages._____ ( _____ );

A

unshift, 23

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

The orderQueue array contains a list of customer orders. Create a new variable named shipping – remove the first item from the array and place it in the shipping variable.

var orderQueue = [‘1XT567437’,’1U7857317’,’1I9222528’];

Now create a new variable named cancelled. Remove the last item from the orderQueue array and store it in the variable cancelled.

A
var shipping = orderQueue.shift();
var cancelled = orderQueue.pop();
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Use a for or while loop to iterate through the values in the temperatures array from the first item – 100 – to the last – 10. Inside the loop, log the current array value to the console.

var temperatures = [100,90,99,80,70,65,30,10];

A
for(var i = 0; i \< temperatures.length; i++) {
  console.log(temperatures[i]); 
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Use the array method that combines all of the items in an array into a single string. In the final string, the array items should be separated by a comma AND a space. Finally, log the final string value to the console.

var months = [‘January’, ‘February’, ‘March’, ‘April’, ‘May’, ‘June’, ‘July’, ‘August’, ‘September’, ‘October’, ‘November’, ‘December’];

A

console.log(months.join(“, “));

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

In this code challenge you need to create a two-dimensional array – an array of arrays. Start by creating an empty array literal named coordinates.

A two-dimensional Array is an array of arrays. Add 1 array to the coordinates array. That new array should have two items in it.

Add three more arrays to the coordinates array. The coordinates array should have 4 arrays in it – each of those arrays should have 2 items in it.

A

var coordinates = [
[“item”, “item”],
[“item”, “item”],
[“item”, “item”],
[“item”, “item”]
];

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Finish the code by adding the array method that combines all of the items in an array into a single string.

var students = [“Sally”, “Joan”, “Raphael”, “Sam”]; var message = “Hello “ + students._____(“, “);

A

join

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

The following code should print out each item in the array times, but there’s one part is missing. Finish the code to log out each array item to the console:

var times = [1.22, 1.75, 2.10, 2.55];

for (var i=0; i < times.length; i += 1 ) {

console.log(times[_____]);

}

A

i

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What array method combines one array with another to create a new array?

A

concat();

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Say you have two arrays – oldScores and newScores and you want to combine those two into a new array named allScores. Complete the code so that the new array first has the old scores listed followed by the new scores:

var allScores = _____.concat(_____);

A

oldScores, newScores

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

When the following code runs what will appear in the JavaScript console?

var temperatures = [76.3, 44.9, 56, 89.8, 100.2]; console.log( temperatures.indexOf( 89.8 ) );

A

3

How well did you know this?
1
Not at all
2
3
4
5
Perfectly