-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.ts
64 lines (58 loc) · 1.18 KB
/
index.ts
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
#! /usr/bin/env node
import inquirer from 'inquirer';
let conversion={
"PKR":{
"USD":0.0036,
"GBP":0.0030,
"PKR":1,
"KWD":0.0011
},
"GBP":{
"USD":1.22,
"GBP":1,
"PKR":334.15,
"KWD":0.38
},
"USD":{
"USD":1,
"GBP":0.82,
"PKR":275,
"KWD":0.31
},
"KWD":{
"USD":3.24,
"GBP":2.67,
"PKR":900.90,
"KWD":1
}
}
const answer:{
from:"PKR"|"USD"|"GBP"|"KWD",
to:"PKR"|"USD"|"GBP"|"KWD",
amount:number
}=await inquirer.prompt([
{
type:"list",
name:"from",
choices:["PKR","USD","GBP","KWD"],
message:"select your first currency from"
},
{
type:"list",
name:"to",
choices:["PKR","USD","GBP","KWD"],
message:"select your second currrency to"
},
{
type:"number",
name:"amount",
message:"Enter your conversion amount: "
}
]);
const {from,to,amount}=answer;
if(from && to && amount){
let result = conversion[from][to]*amount;
console.log(`your conversion from ${from} to ${to} = ${result}`);
}else{
console.log("Invalid input");
}