Restaurant have to calcute the final price which include Value Added Tax(VAT) and service charge.
Service charge only calculated for dine in.
We need your help to make a function to calculate the final price.
Note:
-VAT rate is 10%
-service charge rate is 5%
-service charge is taxable
-the final price should be round down.
Example:
-if the price is 100 and take away, the final price would be 110
-if the price is 100 and dine in, the final price would be 105
function finalPrice(price,dineIn) {
var service = 0.05
var VAT = 0.1
if(dineIn == true) {
return Math.floor(price * (1 +service) * (1+ VAT)) }
else {
return Math.floor(price * (1+ VAT))
}
}
// Since Node 10, we're using Mocha.
// You can use `chai` for assertions.
const chai = require("chai");
const assert = chai.assert;
// Uncomment the following line to disable truncating failure messages for deep equals, do:
// chai.config.truncateThreshold = 0;
// Since Node 12, we no longer include assertions from our deprecated custom test framework by default.
// Uncomment the following to use the old assertions:
Test = require("@codewars/test-compat");
describe("Solution", function() {
it("should test for something", function() {
// Test.assertEquals(1 + 1, 2);
assert.equal(finalPrice(100,false), 110);
assert.equal(finalPrice(100,true), 115);
assert.equal(finalPrice(1000,false), 1100);
});
});
A customer pays a goods for 100 (price) and they must pay additonal tax 10 (VAT rate 10%). The final price will be 110.
If the customer pays goods with price greater than or equal 1000, the customers will pay additional luxury tax with rate 30%.
We need your help to make a formula to calculate the final price (include tax).
Information:
VAT rate = 10%
Luxury tax rate* = 30%
*imposed only if the goods and services price greater than or equal 1000
function finalPrice(price) {
var vat = 0.1
var lux = 0.3
if(price >= 1000) {
return Math.floor(price * (1+vat+lux))
} else {
return Math.floor(price * (1+vat))
}
}
const chai = require("chai");
const assert = chai.assert;
const Test = require("@codewars/test-compat");
describe("Solution", function() {
it("Final Price", function() {
assert.equal(finalPrice(100), 110);
assert.equal(finalPrice(100), 110);
assert.equal(finalPrice(1000), 1400);
assert.equal(finalPrice(900), 990);
assert.equal(finalPrice(2000), 2800);
});
});