-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
28 lines (25 loc) · 985 Bytes
/
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
const btnEl = document.getElementById("btn");
const fetchCryptoPrices = async () => {
try {
const response = await fetch(
"https://api.coingecko.com/api/v3/simple/price?ids=bitcoin,ethereum,cardano&vs_currencies=usd"
);
btnEl.disabled = true;
const data = await response.json();
const bitcoinPrice = data.bitcoin.usd;
const ethereumPrice = data.ethereum.usd;
const cardanoPrice = data.cardano.usd;
document.getElementById("bitcoin").innerText = `$${bitcoinPrice}`;
document.getElementById("ethereum").innerText = `$${ethereumPrice}`;
document.getElementById("cardano").innerText = `$${cardanoPrice}`;
btnEl.disabled = false;
} catch (error) {
console.error(error);
btnEl.disabled = false;
document.getElementById(
"error"
).innerText = `🙄 Something is not right, Please try few minutes later.`;
}
};
fetchCryptoPrices();
btnEl.addEventListener("click", fetchCryptoPrices);