Lesson #9 Review Questions

Back to Lesson # 9 - Arrays of Data Back to Main Menu # 9 Assignment

 

 

1. It is best to use an array for:

a numeric variable that is very large and needs a large amount of memory
a large number of similar data items such as a list
only for number crunching and huge calculations
long strings of text with lots of punctuation
2. In JavaScript, if an array is created so that the last element is someData[9], then the statement " someData[10] = 25;" would cause a syntax error.
false
true

3. Finish this statement to create an array called myList to hold 250 items: var myList = ...

new Array(250);
new Array(249);
new array[250];
array(250);

4. If an array called myList contains 25 items, then the statement to store the string "end of file" in the very last position would be:

myList[25] = "end of file";
myList(24) = "end of file";
myList[24] = "end of file";
myList (end of file) = 25;

5. The most natural construct to use in processing an array of data is the:

a post test loop (do...while...)
a switch statement
a pre test loop (while... .)
for loop, using the loop control variable as the index

6. What do these lines of code do, when taken as a group?

    var temp = myList[2];

    myList[2] = myList[3];

    myList[3] = temp;
they test the contents of myList for correct order
they substitute the value of 'temp' for items 2 and 3 in the list
they store two values in the temp variable at once, which is very useful
they swap the values of the 3rd and 4th elements in an array called myList.

7. To find out if a certain piece of data (the target) is stored somewhere in an array, the array must be:

sorted in descending order
sorted in ascending order
placed into permanent storage first
searched
8. A good application for using an array would be which of the following?
a recipe for Ranch Dip
a dice game for the internet
a personal address book
a mouseOver event
9. A formula for generating random numbers between 1 and 25 is:

var someNum = Math.floor(Math.random() * 1 + 25);
var someNum = Math.floor(Math.random() * 25 +1);
10. A bubble sort works by
Searching the array for the largest item
Comparing adjacent items in an array and swapping them if needed.
Starting at the beginning, and going through one by one in order
Comparing the largest item to the middle item, and exiting early if they are already in the correct order.

Return to Top of Page | Back to Main Menu