This repository was archived by the owner on Oct 26, 2020. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 42
Expand file tree
/
Copy path4-tax.js
More file actions
60 lines (50 loc) · 1.5 KB
/
4-tax.js
File metadata and controls
60 lines (50 loc) · 1.5 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
/*
SALES TAX
=========
A business requires a program that calculates how much sales tax to charge
Sales tax is 20% of the price of the product
*/
function calculateSalesTax(gross) {
return gross * 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 transforms numbers into the format £0.00
Remember that the prices must include the sales tax (hint: you already wrote a function for this!)
*/
function formatCurrency(x) {
var net = x * 1.2;
var result = net.toFixed([2]);
return "£" + result;
}
/* ======= TESTS - DO NOT MODIFY =====
There are some Tests in this file that will help you work out if your code is working.
To run these tests type `node 4-tax.js` into your terminal
*/
function test(test_name, expr) {
let status;
if (expr) {
status = "PASSED";
} else {
status = "FAILED";
}
console.log(`${test_name}: ${status}`);
}
test("calculateSalesTax function - case 1 works", calculateSalesTax(15) === 18);
test(
"calculateSalesTax function - case 2 works",
calculateSalesTax(17.5) === 21
);
test(
"calculateSalesTax function - case 3 works",
calculateSalesTax(34) === 40.8
);
test("formatCurrency function - case 1 works", formatCurrency(15) === "£18.00");
test(
"formatCurrency function - case 2 works",
formatCurrency(17.5) === "£21.00"
);
test("formatCurrency function - case 3 works", formatCurrency(34) === "£40.80");