Tracking Data Using Objects Flashcards

1
Q

What is one way to think of a JavaScript object literal?

A

As a package of variables.

A JavaScript object literal is like a series of named variables, each with their own value, packaged into a single item - the object.

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

What code examples would change the weight property?

var animal = { name : “Zebra”, lifeSpan: 25, weight: 770 };

A

animal.weight = 770;

animal[“weight”] = 770;

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

Use a for in loop to log each of the property names of the shanghai object to the console.

var shanghai = {
population: 14.35e6,
longitude: ‘31.2000 N’,
latitude: ‘121.5000 E’,
country: ‘CHN’
};

Now that you are logging out the property names, include the property values too. In other words you want to log out 4 lines that include both the property name and value. For example: “population: 1435e6”

A

for(var key in shanghai) {
console.log(key, “: “, shanghai[key]);
}

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

Inside the array literal, add three object literals. In other words, the objects array should have three values. Each object should have 2 property/value pairs.

var objects = [];

A
var objects = [
  {
    key: "value",
    property: "value"
  },
  {
    key: "value",
    property: "value"
  },
  {
    key: "value",
    property: "value"
  }
];
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Given the following JavaScript code:

var car = {

make: “Ford”,
model: “Fiesta”,
year: 2015

}

for ( property in car ) {

console.log( property );

}

What will you see in the JavaScript console?

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

Given the following JavaScript object:

var student = {

userName: “Dave”,

email: “dave@teamtreehouse.com”,
badges: 130,
points: 14888

}

Which code example will display the values “Dave”, “dave@teamtreehouse.com”, 130 and 14888 to the JavaScript console?

A

for ( var prop in student ) {

console.log( student[prop] );

}

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

What does JSON stand for?

A

JavaScript Object Notation

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

JSON is:

A

a string.

JSON is a string that’s formatted LIKE a JavaScript object literal.

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

Complete the code below to display every property and value of an object named location:

_____ ( property _____ location ) {

document.write(‘

’ + property + ‘:’ + location[property] + ‘

’);

}

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

The indexOf( ) method can search an array to see if there is a matching item in the array. For example, students.indexOf(“Kari”) looks to see if the string “Kari” is an item in the students array. What value does the JavaScript interpreter return if it CAN’T find a matching item in the array?

A

-1

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

Complete the following code to open an alert with the first item in the scores array:

alert( scores[_____] );

A

0

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

Complete the code below. Use a method you were taught in this course to remove the last item from the students array.

var lastStudent = students._____;

A

pop()

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

T/F: A two-dimensional array is an array of objects.

A

False

A two-dimensional array is an array, where each item in the array is another array.

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

Complete the code below to display every property and value of an object named location:

( _____ property _____ location ) {

document.write(‘

’ + property + ‘:’ + location[property] + ‘

’);

}

A

for, in

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