Social Icons

Pages

Wednesday, November 30, 2016

Introduction to Objects I 11/33

Putting it all together
We've learned how to make objects in two different ways. Both are valid, and you can use which one you prefer.
Let's practice how to use both one more time.

Instructions
Use literal notation to finish the snoopyobject. Remember literal notation is the one where we fill in } with separate properties and values with colons. Each property is separated by a comma.
snoopy should have two properties, aspecies of "beagle" and age of 10.
Then make buddy, a 5 year-old golden retriever, using constructor notation. This notation involves using the key word new to create an empty object. Then we fill it in using dot notation.
// help us make snoopy using literal notation
// Remember snoopy is a "beagle" and is 10 years old.
var snoopy ={
    species:"beagle",
    age:10,
};

// help make buddy using constructor notation
// buddy is a "golden retriever" and is 5 years old
var buddy = new Object()
buddy.species="golden retriever";
buddy.age=5;


No comments:

Post a Comment