Advertisement
Crevice

js reference types 1

Nov 12th, 2019
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.38 KB | None | 0 0
  1. //TODO: MAKE SURE YOU LABEL ALL YOUR CONSOLE LOGS
  2.  
  3. /*** OBJECT EXERCISES ***/
  4.  
  5. //create a variable containing an empty object called aboutMe
  6.  
  7. //add a property called "name" with a value of your name as a string
  8.  
  9. //add a property called "favorite animal" with a value of your favorite animal
  10.  
  11. //console log out the "name" and "favorite animal" properties in aboutMe. Was there a difference in syntax needed?
  12.  
  13. //having a space in a property name can be frustrating...
  14. //save the value of the "favorite animal" property into a new property called "favAnimal"
  15. //you MAY NOT hard-code the value, you must pull the value programmatically
  16. //delete the "favorite animal" property entirely (programmatically!)
  17. //this means that if I examine aboutMe in the console, I should not see "favorite animal" as a property at all
  18.  
  19. //create a property of aboutMe called myPet
  20. //this property should contain another object
  21. //give this object a property of "name" and "species" with the appropriate values
  22. //if you do not have a pet, use your imagination! :D
  23.  
  24. //create a new variable called alsoMe
  25. //set its value to the same value as the aboutMe variable
  26. //both the aboutMe and alsoMe variables should contain the same object
  27.  
  28. //change the value of the "name" property in aboutMe to be your superhero name, if you were a superhero
  29.  
  30. //console log out the value of the "name" property in aboutMe and alsoMe. What's different?
  31.  
  32. //create a variable called aWholeNewMe, and give it a value of a COPY of the object in aboutMe
  33. //there are various different ways to do this, but I suggest using a for in loop currently
  34. //first make the aWholeNewMe variable with an empty object
  35. //make a for in loop that loops over each property of aboutMe
  36. //for each property, set a property on aWholeNewMe with the same name and value
  37.  
  38. //set the value of the "name" property in aboutMe back to your real name
  39. //log out the "name" property in aboutMe, alsoMe, and aWholeNewMe
  40. //what is the same? What's different?
  41.  
  42. /****** CHALLENGE MODE ******/
  43.  
  44. //in aboutMe, change the species of your pet to something new.
  45. //log out aboutMe and aWholeNewMe, and compare their pet objects. Is it what you expected? -- try using console.table
  46. //find a way to make a copy of an object so that nested objects are copied too
  47.  
  48. /****** END CHALLENGE MODE ******/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement