-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.ts
56 lines (48 loc) · 1.97 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
#! /usr/bin/env node
// Importing inquirer & chalk
import inquirer from "inquirer";
import chalk from "chalk";
// Printing a welcome msg
let line = chalk.gray('=' .repeat(58));
console.log(`\n\t${line}\n${chalk.bold.blue("\tWelcome to \`Abdul Saboor\` - Currency Converter Application\n")}\t${line}\n`);
// Making an object for the list of currencies and their exchange rates
let exchangeRate: any ={
"USD": 1, // Base Currency (United States Dollar)
"EUR": 0.9, // European Currency (Euro)
"JYP": 155, // Japanese Currency (Yen)
"CAD": 1.4, // Canadian Currency (Canadian Dollar)
"AUD": 1.6, // Australian Currency (Australian Dollar)
"PKR": 278, // Pakistani Currency (Pakistani Rupees)
}
// Process of prompting the user to select currencies & amount to convert
let input = await inquirer.prompt([
{
name: "fromCurrency",
type: "list",
message: (chalk.yellow("Select the Currency to convert from: ")),
choices: ["USD" , "EUR" , "JYP" , "CAD" , "AUD" , "PKR"],
},
{
name: "toCurrency",
type: "list",
message: chalk.yellow("Select the currency to convert to: "),
choices: ["USD" , "EUR" , "JYP" , "CAD" , "AUD" , "PKR"]
},
{
name: "amount",
type: "input",
message: chalk.cyan("Enter the amount of the currency you want to convert:"),
}
])
// Making multiple variables for each input
let fromAmount = exchangeRate[input.fromCurrency];
let toAmount = exchangeRate[input.toCurrency];
let amount = input.amount
// Formula of conversion
let baseAmount = amount / fromAmount
let convertedAmount = baseAmount * toAmount
let caMath = Math.round(convertedAmount * 100) / 100;
// Printing the converted amount
console.log(chalk.green(`\nHere is your converted amount: ${caMath}`));
// Printing a Note
console.log(chalk.red("\n These exchanged rates are based as of 22 april, 2024 after some time if the rates are different feel free to change them! -Abdul Saboor\n"));