-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
42 lines (40 loc) · 1 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
<html>
<head>
<title> App 4 </title>
<style>
*{font-size:40px; }
body { background-color: lightblue; }
h1{ border:solid; width:50%; border-radius:40px; }
</style>
<script>
function convert()
{
event.preventDefault();
let aid = document.getElementById("aid");
let ans = document.getElementById("ans");
let url = "https://api.exchangerate-api.com/v4/latest/USD";
fetch(url)
.then(res => res.json())
.then(data => {
let dollar = data["rates"]["INR"];
let amt_in_dollar = parseFloat(aid.value);
let amt_in_rupees = amt_in_dollar * dollar;
let msg = "\u20b9" + amt_in_rupees.toFixed(2);
ans.innerHTML = msg;
})
.catch(err => ans.innerHTML = "issue " + err);
}
</script>
</head>
<body>
<center>
<h1> Live Currency Converter </h1>
<form onsubmit="convert()">
<input type="number" step="any" placeholder="Enter amount in $$" id="aid" />
<br><br>
<input type="submit" value="Convert"/>
</form>
<h1 id="ans" />
</center>
</body>
</html>