-1

Directions: In the product object that is provided, the cost and deliveryFee are in US dollars. Add a method named newPayments to the product object that sums the cost and deliveryFee and returns the result in cents (multiply by 100). Remember to use this and to return the result.

Currently stuck on this code

let product = {
  cost: 1200,
  deliveryFee: 200,
  newPayments: function(){
    return this.cost + this.deliveryFee * 100;
  }
};

cost and deliveryFee should be added together then multiplied by 100 but it seems unable to add

Ern
  • 21
  • 3
  • 1
    Addition binds less tightly than multiplication, so you need parentheses around the two `+` operands. It's just like in ordinary pencil-and-paper algebra. – Pointy Aug 05 '19 at 16:13

1 Answers1

1

The same way that maths has an order of operations, JavaScript does as well. Wrap your addition in parentheses to fix that.

let product = {
  cost: 1200,
  deliveryFee: 200,
  newPayments: function(){
    return (this.cost + this.deliveryFee) * 100;
  }
};
James Long
  • 4,629
  • 1
  • 20
  • 30