Skip to content

Commit ad7ac6d

Browse files
authored
Merge pull request sanscript-tech#389 from Sapna2001/currency
Currency Convert CLI
2 parents 2b0cfb0 + 52286ba commit ad7ac6d

File tree

3 files changed

+106
-0
lines changed

3 files changed

+106
-0
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Currency Converter CLI
2+
3+
A simple script to convert currencies.</br>
4+
URL used : "https://api.exchangerate-api.com/v4/latest"
5+
6+
## How to use the script ?
7+
8+
Installations:</br>
9+
- readline-sync</br>
10+
npm install readline-sync
11+
- fetch</br>
12+
npm i node-fetch --save</br>
13+
14+
To run the script, run this command in the terminal:</br>
15+
$ node "path_of_the_file"</br>
16+
For example:</br>
17+
$ node "c:\Users\Sapna\Desktop\hacking-tools-scripts\JavaScript\Currency_Converter_CLI\script.js"</br>
18+
19+
## Screenshot
20+
![demo1](https://user-images.githubusercontent.com/56690856/99526338-21f40800-29c1-11eb-9927-eb9070e4fdfc.png)
21+
![demo2](https://user-images.githubusercontent.com/56690856/99526342-24566200-29c1-11eb-88e3-f47b24e07cab.png)
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
fetch
2+
readlineSync
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
const readlineSync = require("readline-sync");
2+
const fetch = require("node-fetch");
3+
4+
// api
5+
const api = "https://api.exchangerate-api.com/v4/latest";
6+
7+
// options for currencies
8+
var options = [
9+
"AED",
10+
"ARS",
11+
"AUD",
12+
"BGN",
13+
"BRL",
14+
"CAD",
15+
"CHF",
16+
"CLP",
17+
"CNY",
18+
"COP",
19+
"CZK",
20+
"DKK",
21+
"EGP",
22+
"EUR",
23+
"FJD",
24+
"GBP",
25+
"GTQ",
26+
"HKD",
27+
"HRK",
28+
"IDR",
29+
"HUF",
30+
"ILS",
31+
"INR",
32+
"ISK",
33+
"JPY",
34+
"KRW",
35+
"KZT",
36+
"MVR",
37+
"MXN",
38+
"MYR",
39+
"NOK",
40+
"NZD",
41+
"PAB",
42+
"PEN",
43+
"PHP",
44+
"PKR",
45+
"PLN",
46+
"PYG",
47+
"RON",
48+
"RUB",
49+
"SAR",
50+
"SEK",
51+
"SGD",
52+
"THB",
53+
"TRY",
54+
"TWD",
55+
"UAH",
56+
"UYU",
57+
"ZAR",
58+
];
59+
60+
console.log("Options available");
61+
62+
// display options
63+
options.forEach(function printOptions(item) {
64+
console.log(item);
65+
});
66+
67+
var fromCurrency = readlineSync.question("From Currency:");
68+
var fromValue = readlineSync.question("Enter Value:");
69+
var toCurrency = readlineSync.question("To Currency:");
70+
var toValue;
71+
72+
// function to convert
73+
function convert() {
74+
fetch(`${api}/${fromCurrency}`)
75+
.then((result) => result.json())
76+
.then((result) => {
77+
const rate = result.rates[toCurrency];
78+
toValue = (fromValue * rate).toFixed(2);
79+
console.log(`${fromValue} ${fromCurrency} = ${toValue} ${toCurrency}`);
80+
});
81+
}
82+
83+
convert();

0 commit comments

Comments
 (0)