This repository was archived by the owner on Jan 14, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 477
Expand file tree
/
Copy path4-tax.js
More file actions
65 lines (50 loc) · 1.87 KB
/
4-tax.js
File metadata and controls
65 lines (50 loc) · 1.87 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
62
63
64
65
/*
SALES TAX
=========
A business requires a program = information
that calculates = what the function will do = the return
how much the price of a product is = step 1
including sales tax = step 2
Sales tax is 20% of the price of the product. = information for step 2
*/
function calculateSalesTax(price) {
return price * 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(price) {
let priceWithTax = calculateSalesTax(price);
return '£' + priceWithTax.toFixed(2);
}
/*
===================================================
======= 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");
});