Manipulating Objects

The Big Idea

You will work with a JavaScript object and manipulate it step by step — adding properties, changing values, deleting properties, and nesting objects — without modifying the original object literal directly.

Your Roadmap

SectionTimeRequired?
Setup5 min⚑ Required
Object anatomy recap5 min⚑ Required
Pass the tests1.5 hrs⚑ Required

Setup

Run the tests for this kata:

npm test 2-manipulate-objects

Object anatomy recap

Here is the object you will be working with:

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

You must complete each task outside the curly braces — do not modify the object itself.

Here is the terminology used in this kata — a quick recap of an object's anatomy:

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

Pass the tests

Each step below matches one test. Complete them in order. After each step, run the tests to confirm it passes before moving on.

Note: Each step is its own line of code, and each builds on the 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.