-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
160 lines (111 loc) · 4.78 KB
/
index.html
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
<!DOCTYPE html>
<html lang="en">
<head>
<style>
body{
margin: 200px;
text-align: center;
background-color: white;
justify-content: center;
}
#div2{
background-color:green;
border: black;
padding: 25px;
text-align: center;
block-size:670px;
justify-content: center;
margin: 300px;
width: 350px;
}
h2{
font-family: sans-serif;
}
html{
justify-content: center;
}
</style>
<title>Currency Exchange</title>
<script>
document.addEventListener('DOMContentLoaded',function(){
document.querySelector('form').onsubmit = function(){
fetch('https://v6.exchangerate-api.com/v6/a840ec47274bed9def64fc2a/latest/USD')
.then(response => response.json())
.then(data => {
const currency = document.querySelector('#currency').value.toUpperCase();
const rate = data.conversion_rates[currency];
if (rate !==undefined){
document.querySelector('#res').innerHTML = `1 USD is equal to ${rate.toFixed(4)} ${currency}`
} else {
document.querySelector('#res').innerHTML = 'Invalid Currency';
}
})
.catch(error => {
console.log('Error', error);
});
return false;
}
document.querySelector('#form2').onsubmit = function(){
fetch('https://v6.exchangerate-api.com/v6/a840ec47274bed9def64fc2a/latest/USD')
.then(response => response.json())
.then(data => {
const Curr = document.querySelector("#Curr").value.toUpperCase();
const Val = parseInt(document.querySelector("#Val").value);
const curr_rate = data.conversion_rates[Curr];
console.log(curr_rate)
const result = Val * curr_rate
console.log(result)
if (curr_rate !==undefined){
document.querySelector("#restext").innerHTML = `${Val} USD is equal to ${result} ${Curr} `;
} else {
document.querySelector('#restext').innerHTML = 'Invalid Currency';
}
})
.catch(error => {
console.log('Error', error);
});
return false;
}
});
</script>
</head>
<body>
<div id="div2">
<div id="div1">
<h2 id="heading">Fx Rates Converter </h2>
</div>
<form>
<input id="currency" placeholder="Input Currency" type="text" ><br>
<input type="submit" value="Convert">
</form>
<div id="result">
<hr>
<h2 id="res">
</h2>
<hr>
Note : Input the Currency Code e.g for Euro input 'EUR'
<br>
Note : Base currency = USD
<br>
<br>
<br>
Developed by Dave Eke - [email protected]
<br>
<br>
<br>
<form id="form2">
<input id="Curr" type="text" placeholder="Input Currency Code">
<input id="Val" type="text"placeholder="Input Value in USD"><br>
<input type="submit" value="Calculate">
</form>
<br>
<br>
Note : The value you put in the "Input Value " space is in USD!<br>
I.e you are calculating from USD to your desired currency.
<hr>
<h1 id="restext"></h1>
<hr>
</div>
</div>
</body>
</html>