Code Lab

First object

EasyObjects3 min

Write a function editUser(user) that gets a user object.

Add the property surname with the value 'Smith', change name to 'Pete' and delete the property age. Leave the other properties as they are. Return the same object.

Examples

editUser({ name: 'John', age: 30 })

Returns { name: 'Pete', surname: 'Smith' }

editUser({ name: 'Ann', city: 'Oslo' })

Returns { name: 'Pete', city: 'Oslo', surname: 'Smith' }

The property `city` stays.

Source

Loading the editor...
  1. InputeditUser({ name: 'John', age: 30 })
    Expected{ name: 'Pete', surname: 'Smith' }
  2. InputeditUser({ name: 'Ann', city: 'Oslo' })
    Expected{ name: 'Pete', city: 'Oslo', surname: 'Smith' }
  3. Returns the same object

Hidden tests run on Submit.