Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //TODO: MAKE SURE YOU LABEL ALL YOUR CONSOLE LOGS
- /*** OBJECT EXERCISES ***/
- //create a variable containing an empty object called aboutMe
- //add a property called "name" with a value of your name as a string
- //add a property called "favorite animal" with a value of your favorite animal
- //console log out the "name" and "favorite animal" properties in aboutMe. Was there a difference in syntax needed?
- //having a space in a property name can be frustrating...
- //save the value of the "favorite animal" property into a new property called "favAnimal"
- //you MAY NOT hard-code the value, you must pull the value programmatically
- //delete the "favorite animal" property entirely (programmatically!)
- //this means that if I examine aboutMe in the console, I should not see "favorite animal" as a property at all
- //create a property of aboutMe called myPet
- //this property should contain another object
- //give this object a property of "name" and "species" with the appropriate values
- //if you do not have a pet, use your imagination! :D
- //create a new variable called alsoMe
- //set its value to the same value as the aboutMe variable
- //both the aboutMe and alsoMe variables should contain the same object
- //change the value of the "name" property in aboutMe to be your superhero name, if you were a superhero
- //console log out the value of the "name" property in aboutMe and alsoMe. What's different?
- //create a variable called aWholeNewMe, and give it a value of a COPY of the object in aboutMe
- //there are various different ways to do this, but I suggest using a for in loop currently
- //first make the aWholeNewMe variable with an empty object
- //make a for in loop that loops over each property of aboutMe
- //for each property, set a property on aWholeNewMe with the same name and value
- //set the value of the "name" property in aboutMe back to your real name
- //log out the "name" property in aboutMe, alsoMe, and aWholeNewMe
- //what is the same? What's different?
- /****** CHALLENGE MODE ******/
- //in aboutMe, change the species of your pet to something new.
- //log out aboutMe and aWholeNewMe, and compare their pet objects. Is it what you expected? -- try using console.table
- //find a way to make a copy of an object so that nested objects are copied too
- /****** END CHALLENGE MODE ******/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement