Review Test Submission: Review 5: Arrays & Objects

0.0(0)
studied byStudied by 0 people
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
Card Sorting

1/11

encourage image

There's no tags or description

Looks like no tags are added yet.

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

12 Terms

1
New cards

What is an array

An array is able to store more than one value in a single variable.

2
New cards

Which of the following is the correct way to declare an array?

var myFriends = ["Joe", "Jane"];

3
New cards

For the array cities, with members Boston and New York (in that order), you would refer to Boston as cities[0].

True

4
New cards

myFriends.length will have the value of the number of items in the array myFriends.

TrueThe length property returns the total number of elements in an array.

5
New cards


declare an array called vegetables that will store the following vegetables:  broccoli, peas, and carrots.


var vegetables = ["broccoli", "peas", "carrots"];

6
New cards

use a loop to display the following items in this array, each on a separate line:  cards = ["ace", "king", "queen", "jack"];

var y = 20;

for(var i=0; i<3; i++){

     fill(255,0,0);

     text(cards[i], 20, y);

    y =+20;

}

7
New cards


if you wish to add a value to the end of an array, you can use the pop command.

false

8
New cards

You would like to remove the last item in the cards array, and replace it with a "ten".  List the two commands needed to do that.

cards.pop();

card.push("ten");

9
New cards

If you wish to display the number of items in the cards array in the sentence, I have <number of cards> in my hands, you could do it like this:

fill(255, 0, 0);

text("I have " + cards.length + " in my hands.", 20, 20);

true You would need to use the length property of the array to display the number of items.

10
New cards

Here are two variables about the same person, Jim:

var jimName = "Jim";

var jimAge = 19;

If you wanted to create an object, called jim, and put those two variables inside, which of the following would be the correct way?

var jim = {  

   jimName: "Jim",

   jimAge: 19

};

11
New cards

an object can contain an array, and an array can contain an object.

true

12
New cards

Selected Answer:

Here are three variables about the same person:

var name = "Sara";

var favFood = "eggs";

var age = 22;

Create an object, called Sara, to store each of those variables.

Display each value, by referring to the object, in two sentences, on separate lines.

They should look like this:

Sara is 22 years old.

Sara's favorite food is eggs.

var Sara = {

name: "Sara",

favFood:  "eggs",

age:  22

};

fill(255,0,0);

text(Sara.name + " is " + Sara.age + " years old.", 20, 20);

text(Sara.name + "'s favorite food " + " is " + Sara.favFood, 20, 40);