What we're doing today is writing functions that can manipulate the object passed in.
- Fork
- Clone
- Install dependencies with
npm install - Run the tests with
npm run test
-
getFirstName- returns the value of the firstName property of the given person objectgetFirstName({firstName: 'Colin', lastName: 'Jaffe'}) // -> 'Colin'getFirstName({firstName: 'Petra', lastName: 'Solano'}) // -> 'Petra'
-
getLastName- returns the value of the lastName property of the given person objectgetLastName({firstName: 'Colin', lastName: 'Jaffe'}) // -> 'Jaffe'getLastName({firstName: 'Petra', lastName: 'Solano'}) // -> 'Solano'
-
getFullName- returns the value of the firstName property plus the lastName property with a space in the middle for the given person objectgetFullName({firstName: 'Colin', lastName: 'Jaffe'}) // -> 'Colin Jaffe'getFullName({firstName: 'Petra', lastName: 'Solano'}) // -> 'Petra Solano'
-
setFirstName- changes the value of the firstName property of the given person object to the given valuesetFirstName({firstName: 'Colin', lastName: 'Jaffe'}, 'Redacted') // -> {firstName: 'Redacted', lastName: 'Jaffe'}setFirstName({firstName: 'Petra', lastName: 'Solano'}, 'Anthony') // -> {firstName: 'Anthony', lastName: 'Solano'}
-
setAge- changes the value of the age property of the given person object to the given valuesetAge({firstName: 'Colin', lastName: 'Jaffe', age: 39}, 45) // -> {firstName: 'Colin', lastName: 'Jaffe', age: 45}setAge({firstName: 'Petra', lastName: 'Solano', age: 29}, 35) // -> {firstName: 'Petra', lastName: 'Solano', age: 35}
-
giveBirthday- increments by 1 the age property of the given person object, or gives them an age of 1 if they don't have that propertygiveBirthday({firstName: 'Colin', lastName: 'Jaffe', age: 39}) // -> {firstName: 'Colin', lastName: 'Jaffe', age: 40}giveBirthday({firstName: 'Petra', lastName: 'Solano', age: 29}) // -> {firstName: 'Solano', lastName: 'Solano', age: 30}giveBirthday({firstName: 'Baby', lastName: 'Jaffe'}) // -> {firstName: 'Baby', lastName: 'Jaffe', age: 1}
-
marry- sets the marital status of both given people totrueand sets each person'sspouseNameproperty to be the full name of the other
const person1 = {firstName: 'Colin', lastName: 'Jaffe', married: false}
const person2 = {firstName: 'Petra', lastName: 'Solano', married: false}
marry(person1, person2)
console.log(person1) // -> {firstName: 'Colin', lastName: 'Jaffe', married: true, spouseName: 'Petra Solano'}
console.log(person2) // -> {firstName: 'Petra', lastName: 'Solano', married: true, spouseName: 'Colin Jaffe'}
divorce- changes the marital status tofalseand removes thespouseNameproperty from both given people
const person1 = {firstName: 'Colin', lastName: 'Jaffe', married: true, spouseName: 'Petra Solano'}
const person2 = {firstName: 'Petra', lastName: 'Solano', married: true, spouseName: 'Colin Jaffe'}
divorce(person1, person2);
console.log(person1) // -> {firstName: 'Colin', lastName: 'Jaffe', married: false}
console.log(person2) // -> {firstName: 'Petra', lastName: 'Solano', married: false}
- For
getFullName, don't set afullNameproperty on the given object. Just give the caller of the function back a new value based on the first name and last name - For
giveBirthday, you'll need to have some way to tell if the keyageis already in the given person - For
marry, you can re-use yourgetFullNamefunction in order to get each person'sspouseName. Just pass in the person whosefullNameyou want, and you'll get back your newspouseNameproperty - Same as above for
divorce; you'll need to research a way to REMOVE the keyspouseNamefrom the given people. Simply setting the properties toundefinedornullwon't be sufficient