-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path4-tax.js
More file actions
61 lines (48 loc) · 1.78 KB
/
4-tax.js
File metadata and controls
61 lines (48 loc) · 1.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
/*
SALES TAX
=========
A business requires a program that calculates how much the price of a product is including sales tax
Sales tax is 20% of the price of the product.
*/
function calculateSalesTax(sales) {
return sales * 1.2;
}
/*
CURRENCY FORMATTING
===================
The business has informed you that prices must have 2 decimal places
They must also start with the currency symbol
Write a function that adds tax to a number, and then transforms the total into the format £0.00
Remember that the prices must include the sales tax (hint: you already wrote a function for this!)
*/
function addTaxAndFormatCurrency(tax) {
let newPrice = calculateSalesTax(tax);
let showPrice = newPrice.toFixed(2);
return "£" + showPrice;
}
/*
===================================================
======= TESTS - DO NOT MODIFY BELOW THIS LINE =====
There are some Tests in this file that will help you work out if your code is working.
To run the tests for just this one file, type `npm test -- --testPathPattern 4-tax` into your terminal
(Reminder: You must have run `npm install` one time before this will work!)
===================================================
*/
test("calculateSalesTax for £15", () => {
expect(calculateSalesTax(15)).toEqual(18);
});
test("calculateSalesTax for £17.50", () => {
expect(calculateSalesTax(17.5)).toEqual(21);
});
test("calculateSalesTax for £34", () => {
expect(calculateSalesTax(34)).toEqual(40.8);
});
test("addTaxAndFormatCurrency for £15", () => {
expect(addTaxAndFormatCurrency(15)).toEqual("£18.00");
});
test("addTaxAndFormatCurrency for £17.50", () => {
expect(addTaxAndFormatCurrency(17.5)).toEqual("£21.00");
});
test("addTaxAndFormatCurrency for £34", () => {
expect(addTaxAndFormatCurrency(34)).toEqual("£40.80");
});