-
-
Notifications
You must be signed in to change notification settings - Fork 43
Expand file tree
/
Copy pathexchange.js
More file actions
20 lines (19 loc) · 848 Bytes
/
exchange.js
File metadata and controls
20 lines (19 loc) · 848 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
document.addEventListener('DOMContentLoaded',function(){
document.querySelector('form').onsubmit= function(){
let currency = document.querySelector('#currency').value;
//Fetches the data from the api
fetch('https://api.exchangeratesapi.io/v1/latest?access_key=678f3ff1f6636858c45f550e387554e7&format=1')
//Converts that to JSON model
.then(response => response.json())
//Performs operation on that JSON model
.then(data => {
const current = data.rates[currency];
if(current != undefined){
document.querySelector('#result').innerHTML=`1 EUR is equal to ${current} ${currency}`
}else{
document.querySelector('#result').innerHTML=`Invalid currency input`
}
})
return false;
}
})