Compare commits
No commits in common. "12e5b11ab42625b033f1f8a6e040cce6f0f5660c" and "8cfb75b8d58abeebb7ad00efb51dcc038c99e1b1" have entirely different histories.
12e5b11ab4
...
8cfb75b8d5
|
@ -1,17 +0,0 @@
|
||||||
<!DOCTYPE html>
|
|
||||||
<html lang="it" dir="ltr">
|
|
||||||
<head>
|
|
||||||
<meta charset="utf-8">
|
|
||||||
<title>Form Fetch API</title>
|
|
||||||
<script src="fetch-form-api.js" charset="utf-8"></script>
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
<p>Inserisci una valuta per ottenere i tassi di cambio con l'Euro</p>
|
|
||||||
<form id="form">
|
|
||||||
<input type="text" id="currency" placeholder="Valuta">
|
|
||||||
<input type="submit" value="Converti">
|
|
||||||
</form>
|
|
||||||
<hr>
|
|
||||||
<h2 id="exchange-result"></h2>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
|
@ -1,30 +0,0 @@
|
||||||
function getJSON(response){
|
|
||||||
let data = response.json();
|
|
||||||
return data
|
|
||||||
}
|
|
||||||
|
|
||||||
function getCurrencyRate(currency){
|
|
||||||
console.log(currency);
|
|
||||||
let url = "https://api.exchangeratesapi.io/latest?symbols=" + currency;
|
|
||||||
fetch(url)
|
|
||||||
.then(getJSON)
|
|
||||||
.then(data => {
|
|
||||||
console.log("Data : " ,data)
|
|
||||||
let rate = Object.values(data.rates)[0];
|
|
||||||
document.querySelector("#exchange-result").innerHTML = `1.00 Euro corrisponde a ${rate} ${currency}`;
|
|
||||||
})
|
|
||||||
.catch( err => {
|
|
||||||
// console.log("Errore : ", err)
|
|
||||||
document.querySelector("#exchange-result").innerHTML = `Errore ${err}`;
|
|
||||||
})
|
|
||||||
}
|
|
||||||
document.addEventListener("DOMContentLoaded", () =>{
|
|
||||||
document.querySelector("#form").onsubmit = event =>{
|
|
||||||
event.preventDefault();
|
|
||||||
|
|
||||||
const currency = document.querySelector("#currency").value;
|
|
||||||
getCurrencyRate(currency)
|
|
||||||
|
|
||||||
document.querySelector("#currency").value = "";
|
|
||||||
}
|
|
||||||
})
|
|
Loading…
Reference in New Issue