-2

I'm asked to the following tasks but am having difficulty returning values.
Here's the code:

function calculateTaxes(price, quantity) {
    var salesTax = .10;
    var totalPrice;
    return totalPrice;
}

// Test Your Code Here
calculateTaxes(1,10);
  • calculateTaxes(1,10) should return a number
  • calculateTaxes(2,5) should return a value of 11
  • calculateTaxes(5,6) should return a value of 33
  • calculateTaxes(10,3) should return a value of 33
  • calculateTaxes(15,12) should return a value of 198
  • calculateTaxes(25,2) should return a value of 55
Nisarg Shah
  • 14,151
  • 6
  • 34
  • 55
PreYVin
  • 1
  • 1
  • 6

1 Answers1

1

It's quite straightforward. price*quantity gives you the total price without tax, and multiplying that with 1 + salesTax gives you the price after tax.

function calculateTaxes(price, quantity) {
    var salesTax = .10;
    var totalPrice = (price * quantity) * (1 + salesTax);
    return totalPrice;
}

console.log(calculateTaxes(1,10));
console.log(calculateTaxes(25,2));

Don't be surprised if you see 55.00000001 instead of 55 though. Do read: Is floating point math broken?

Nisarg Shah
  • 14,151
  • 6
  • 34
  • 55
  • @Deepak Kamat, or you can mind your own business instead of trolling. If your not helping don't say anything. Anyone can be a critic. – PreYVin Jan 20 '18 at 06:47
  • @Nisarg Shaw Worked awesome. Thank u. – PreYVin Jan 20 '18 at 06:57
  • @PreYVin I don't mean to be rude but your question doesn't follow community guidelines. This isn't a homework sharing Q&A site to be brutally honest. – Deepak Kamat Jan 20 '18 at 17:48
  • Yeah well this is a community of developers that are responsible for the learning process. If you can't understand that or incapable of helping, don't bother. If you want to be cyberpolice for every forum, be my guest. – PreYVin Jan 21 '18 at 13:27
  • Guys this is not constructive. The question is fairly straightforward and answerable. A lot of people may not find it helpful to future readers, and that's why it might have received downvotes. But there's no point discussing it here. Feel free to delete your comments, unless you feel it adds value to the question at hand. – Nisarg Shah Jan 21 '18 at 14:35