Manipulating Objects

Learning Competencies

  • Define local variables in JavaScript
  • Create, add properties to, delete properties from, and access values from JavaScript Object literals
  • Use pre-written tests to drive development

Time Box

ActivityTime
Kata1.5 hours
Reflect10 minutes

Summary

In this challenge, you will work with the following JavaScript object that has been assigned to the variable terah. You will have to complete each task without modifying the object itself. That means everything must be done outside of the curly braces.

const terah = {
name: "Terah",
age: 32,
height: 172,
hairColor: "brown",
eyeColor: "brown",
};

There is some jargon used in this kata, so here's a quick recap of an object's anatomy:

Code: breakdown of an object, featuring object name, key, value, and property.

Pass the Tests

The steps below match the order of the tests you will need to complete. After completing each step, run your code to ensure that the next test passes.

Note that each step below should be its own line of code in sequential order (i.e. each step will build on any of your code before it).

  1. Define a variable adam and use object literal notation to assign this variable the value of an object with no properties.

  2. Give the adam object a name key that has the value "Adam".

  3. Add a spouse key to terah and assign it the value of adam.

  4. Change the value of the terah age property to 33.

  5. Remove the eyeColor property from terah (hint: use the delete operator).

  6. Add a spouse key to the adam object and assign it the value of terah.

  7. Add a children key to terah and use object literal notation to assign this variable to an empty object.

  8. Add a ben property to the value of the terah children property. ben should be an object with the key name and the value "Ben".

  9. Add a wilson property to the value of the terah children property. wilson should be an object with the key name with the value "Wilson".

  10. Add a felicia property to the value of the terah children property. felicia should be an object with the key name with the value "Felicia".

  11. Add a children property to adam and assign it the value of terah.children.

Your final terah object will be logged to the console when all the tests have passed.