-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex_demo.html
35 lines (28 loc) · 901 Bytes
/
index_demo.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
<!DOCTYPE html>
<html>
<head>
<title>Hello world</title>
</head>
<body>
<h1>Currency Facts</h1>
<input id="currency" type="text" />
<input id="amount" type="text" />
<button id="submit" type="button">Submit</button>
<p id="contents"></p>
<script type="text/javascript">
var currency = document.getElementById('currency');
var amount = document.getElementById('amount');
document.getElementById('submit').addEventListener('click', function (evt) {
var url = `/currencies/${currency.value}?value=${amount.value}`;
var input = document.getElementById('currency');
var country = input.value;
fetch(url).then(function (res) {
return res.json().then(function (contents) {
var string = `${amount.value} USD = ${contents.converted} ${contents.currency}`;
document.getElementById('contents').innerHTML = string;
});
});
});
</script>
</body>
</html>