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 476
Expand file tree
/
Copy path1-currency-conversion.js
More file actions
45 lines (36 loc) · 1.41 KB
/
1-currency-conversion.js
File metadata and controls
45 lines (36 loc) · 1.41 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
/*
CURRENCY CONVERSION
===================
The business is breaking out into a new market and need to convert prices to USD
Write a function that converts a price to USD (exchange rate is 1.4 $ to £)
*/
function convertToUSD(price) {
return Number((price * 1.4).toFixed(2));
}
/*
CURRENCY CONVERSION
===================
The business is now breaking into the Brazilian market
Write a new function for converting to the Brazilian real (exchange rate is 5.7 BRL to £)
They have also decided that they should add a 1% fee to all foreign transactions, which means you only convert 99% of the £ to BRL.
*/
function convertToBRL(price) {
return Number(((price * 5.7)*0.99).toFixed(2));
}
/* ======= TESTS - DO NOT MODIFY =====
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 1-currency-conversion` into your terminal
(Reminder: You must have run `npm install` one time before this will work!)
*/
test("convertToUSD function works for £32", () => {
expect(convertToUSD(32)).toEqual(44.8);
});
test("convertToUSD function works for £50", () => {
expect(convertToUSD(50)).toEqual(70);
});
test("convertToBRL function works for £30", () => {
expect(convertToBRL(30)).toEqual(169.29);
});
test("convertToBRL function works for £1.50", () => {
expect(convertToBRL(1.5)).toEqual(8.46);
});