Defining functions & methods

Question:

I still cannot figure out why this code is not working. When I attempt to call a function.
Repl link:

const introducer = (name, shirt) => {
  const person = {
    name: name,
    shirt: shirt,
    assets: 100000,
    liabilities: 50000,
    netWorth: function () {
      return this.assets - this.liabilities
    }
  }
  
  const intro = 'Hi, my name is ${person.name} and the color of my shirt is ${person.shirt} and my net worth is $${person.networth()} USD'  

  return intro
}

console.log(introducer('James', 'black'))
console.log(introducer('Samuel', 'shirt'))
1 Like

Try fixing your line to be

const intro = `Hi, my name is ${person.name} and the color of my shirt is ${person.shirt} and my net worth is $${person.netWorth()} USD`

I changed it so it uses backticks instead of quotes, and networth is spelled wrong, so I have fixed it all. Should work now

2 Likes

The problem is that you used ' instead of `

2 Likes

That does not seem to change anything besides a result of errors

Use mine, I tested it and it works.