Krypto Preis Checker
Bitcoin (BTC)
$0.00
Empfehlung: –
async function fetchCryptoPrice() {
const apiUrl = ‚https://api.coingecko.com/api/v3/simple/price?ids=bitcoin&vs_currencies=usd‘;
try {
const response = await fetch(apiUrl);
if (!response.ok) {
throw new Error(‚Netzwerkantwort war nicht ok‘);
}
const data = await response.json();
const price = data.bitcoin.usd;
document.getElementById(‚crypto-price‘).innerText = `$${price.toFixed(2)}`;
} catch (error) {
console.error(‚Es gab ein Problem mit der Fetch-Operation:‘, error);
document.getElementById(‚crypto-price‘).innerText = ‚Fehler beim Laden des Preises‘;
}
}
// Ruft den Preis beim Laden der Seite ab
document.addEventListener(‚DOMContentLoaded‘, fetchCryptoPrice);