-
Description handle case when there is a decimal expected (e.g. 101 -> 111.1)
Code function finalPrice(price) { const vat = 0.1; const lux = 0.3; const luxThreshold = 1000; const extra = price >= luxThreshold ? lux : 0; return Number.parseFloat(price * (1 + vat + extra)).toFixed(2); }
Preloaded Code function finalPrice(price) { //good luck }
Test Cases 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); assert.equal(finalPrice(101), 111.1); }); });
Output:
-
Code - function finalPrice(price) {
- const vat = 0.1;
- const lux = 0.3;
- const luxThreshold = 1000;
- const extra = price >= luxThreshold ? lux : 0;
return Math.round(price * (1 + vat + extra));- return Number.parseFloat(price * (1 + vat + extra)).toFixed(2);
- }
Test Cases - 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);- assert.equal(finalPrice(2000), 2800);
- assert.equal(finalPrice(101), 111.1);
- });
- });
- All
- {{group.name}} ({{group.count}})
This comment has been reported as {{ abuseKindText }}.
Show
This comment has been hidden. You can view it now .
This comment can not be viewed.
- |
- Reply
- Edit
- View Solution
- Expand 1 Reply Expand {{ comments?.length }} replies
- Collapse
- Remove
- Remove comment & replies
- Report
{{ fetchSolutionsError }}