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 path1-currency-conversion.js
More file actions
51 lines (43 loc) · 1.54 KB
/
1-currency-conversion.js
File metadata and controls
51 lines (43 loc) · 1.54 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
/*
CURRENCY FORMATTING
===================
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(AmountToConvert) {
var usDollarEquivlent = AmountToConvert * 1.4;
return usDollarEquivlent; //.toFixed(2);
}
/*
CURRENCY FORMATTING
===================
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
Find a way to add 1% to all currency conversions (think about the DRY principle)
*/
function convertToBRL(AmountToConvert) {
var realBrazilianEquivlent = AmountToConvert * 5.7;
realBrazilianEquivlent = addOnePercentFee(realBrazilianEquivlent);
return realBrazilianEquivlent; //.toFixed(2);
}
function addOnePercentFee(transactionAmount) {
var fee = transactionAmount * 0.01;
transactionPlusFee = transactionAmount + fee;
return transactionPlusFee;
}
/* ======= 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 1-currency-conversion` into your terminal
*/
function test(test_name, expr) {
let status;
if (expr) {
status = "PASSED";
} else {
status = "FAILED";
}
console.log(`${test_name}: ${status}`);
}
test("convertToUSD function works", convertToUSD(32) === 44.8);
test("convertToBRL function works", convertToBRL(30) === 172.71);