Skip to content

Commit

Permalink
Create script.js
Browse files Browse the repository at this point in the history
  • Loading branch information
Harish-2003 authored Sep 26, 2024
1 parent 5655509 commit 0f96d7f
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
document.getElementById("predict-btn").addEventListener("click", function() {
let crypto = document.getElementById("crypto").value.toUpperCase();
if (crypto) {
fetch(`https://api.coingecko.com/api/v3/simple/price?ids=${crypto}&vs_currencies=usd`)
.then(response => response.json())
.then(data => {
if (data[crypto.toLowerCase()]) {
document.getElementById("price").innerText = "$" + data[crypto.toLowerCase()].usd;
} else {
document.getElementById("price").innerText = "Cryptocurrency not found!";
}
})
.catch(error => {
document.getElementById("price").innerText = "Error fetching price data.";
console.error("Error:", error);
});
} else {
document.getElementById("price").innerText = "Please enter a valid cryptocurrency symbol.";
}
});

0 comments on commit 0f96d7f

Please sign in to comment.