blackfalcon / learningjs.anotheruiguy.com

Learning the things that drive me crazy ...
1 stars 0 forks source link

Function that takes an object #14

Closed blackfalcon closed 6 years ago

blackfalcon commented 7 years ago

Functions can take an object as its argument. Work up an example that illustrated a function consuming an object for its return.

const myData = {
  name: 'Dale',
  job: 'developer',
  age: 44
}

function overTheHill(obj) {
  let str = '';

  if (obj.age > 45) {
    str = `${obj.name} is too damn old to be a ${obj.job}`
  } else {
    str = `${obj.name} is in the prime of his ${obj.job} career`
  }

  return str
}

var person = overTheHill(myData);

console.log(person)