1/11
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced |
---|
No study sessions yet.
What is an array
An array is able to store more than one value in a single variable.
Which of the following is the correct way to declare an array?
var myFriends = ["Joe", "Jane"];
For the array cities, with members Boston and New York (in that order), you would refer to Boston as cities[0].
True
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.
|
var vegetables = ["broccoli", "peas", "carrots"];
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;
}
|
false
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");
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.
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
};
an object can contain an array, and an array can contain an object.
true
|
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.