-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
25 lines (21 loc) · 873 Bytes
/
app.js
File metadata and controls
25 lines (21 loc) · 873 Bytes
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
document.addEventListener('DOMContentLoaded', function(){
document.querySelector('form').onsubmit = function()
{
//GET request to URL
fetch('https://api.exchangeratesapi.io/latest?base=USD')
.then(response => response.json())
.then(data => {
const currency = document.querySelector('#currency').value.toUpperCase();
const rate = data.rates[currency];
if(rate !==undefined) {
document.querySelector('#result').innerHTML = `1 USD is equal to ${rate.toFixed(2)} ${currency}`
} else {
document.querySelector('#result').innerHTML = 'Invalid Currency!';
}
})
.catch (error => {
console.log('Error:', error);
})
return false;
}
})