added refresh interval to Bitcoin Price
This commit is contained in:
parent
a3a60d2c1d
commit
3dd177f0f3
@ -1,4 +1,5 @@
|
|||||||
// Fetch the Bitcoin price from the CoinGecko API
|
// Function to fetch and update the Bitcoin price
|
||||||
|
function updateBitcoinPrice() {
|
||||||
fetch('https://api.coingecko.com/api/v3/simple/price?ids=bitcoin&vs_currencies=usd')
|
fetch('https://api.coingecko.com/api/v3/simple/price?ids=bitcoin&vs_currencies=usd')
|
||||||
.then(response => response.json())
|
.then(response => response.json())
|
||||||
.then(data => {
|
.then(data => {
|
||||||
@ -22,3 +23,13 @@ fetch('https://api.coingecko.com/api/v3/simple/price?ids=bitcoin&vs_currencies=u
|
|||||||
dollarsToSatsElement.textContent = `$1.00 = ${sats.toFixed(0)} sats`; // Display the result
|
dollarsToSatsElement.textContent = `$1.00 = ${sats.toFixed(0)} sats`; // Display the result
|
||||||
})
|
})
|
||||||
.catch(error => console.error(error));
|
.catch(error => console.error(error));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Function to refresh the Bitcoin price every 30 seconds
|
||||||
|
function refreshBitcoinPrice() {
|
||||||
|
updateBitcoinPrice(); // Call the function immediately to display the price on page load
|
||||||
|
setInterval(updateBitcoinPrice, 10000); // Call the function every 30 seconds (30,000 milliseconds)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Call the function to refresh the Bitcoin price
|
||||||
|
refreshBitcoinPrice();
|
Loading…
Reference in New Issue
Block a user