-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
50 lines (47 loc) · 1.47 KB
/
script.js
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
function convertCurrency() {
const USD_TO_EUR = 0.92;
const USD_TO_GBP = 0.76;
const EUR_TO_USD = 1.09;
const EUR_TO_GBP = 0.83;
const GBP_TO_USD = 1.32;
const GBP_TO_EUR = 1.2;
const USD_TO_INR = 83.23;
const conversionType = document.getElementById("conversion-type").value;
const amount = parseFloat(document.getElementById("amount").value);
let result = 0;
let resultText = "";
switch (conversionType) {
case "1":
result = amount * USD_TO_EUR;
resultText = `${amount} USD is ${result.toFixed(2)} EUR`;
break;
case "2":
result = amount * USD_TO_GBP;
resultText = `${amount} USD is ${result.toFixed(2)} GBP`;
break;
case "3":
result = amount * EUR_TO_USD;
resultText = `${amount} EUR is ${result.toFixed(2)} USD`;
break;
case "4":
result = amount * EUR_TO_GBP;
resultText = `${amount} EUR is ${result.toFixed(2)} GBP`;
break;
case "5":
result = amount * GBP_TO_USD;
resultText = `${amount} GBP is ${result.toFixed(2)} USD`;
break;
case "6":
result = amount * GBP_TO_EUR;
resultText = `${amount} GBP is ${result.toFixed(2)} EUR`;
break;
case "7":
result = amount * USD_TO_INR;
resultText = `${amount} USD is ${result.toFixed(2)} INR`;
break;
default:
resultText = "Invalid choice.";
break;
}
document.getElementById("result").innerText = resultText;
}