-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
19 lines (16 loc) · 735 Bytes
/
script.js
File metadata and controls
19 lines (16 loc) · 735 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
async function fetchData() {
try {
const response = await fetch("https://api.nbp.pl/api/exchangerates/rates/c/sek/");
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
const record = await response.json();
document.getElementById("currency").textContent = record.code;
document.getElementById("price").textContent = record.rates[0].bid;
} catch (error) {
console.error("Failed to fetch currency data:", error);
document.getElementById("currency").textContent = "Error";
document.getElementById("price").textContent = "Failed to load";
}
}
document.addEventListener('DOMContentLoaded', fetchData);