-
Notifications
You must be signed in to change notification settings - Fork 90
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b75a226
commit 839aa6a
Showing
5 changed files
with
118 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# Cryptocurrency API | ||
|
||
This project is a simple web application that fetches and displays the current price of a cryptocurrency using a public API. | ||
|
||
## Features | ||
|
||
- Input a cryptocurrency name to fetch its current price in USD. | ||
- Display the fetched data on the web page. | ||
|
||
## Technologies Used | ||
|
||
- HTML | ||
- CSS | ||
- JavaScript | ||
- [CoinGecko API](https://www.coingecko.com/en/api) | ||
|
||
## How to Run | ||
|
||
1. Clone the repository or download the files. | ||
2. Open the `index.html` file in your web browser. | ||
3. Enter a cryptocurrency name (e.g., `bitcoin`, `ethereum`) in the input box and click the "Get Data" button to see the current price. | ||
|
||
## Example Usage | ||
|
||
- Input: `bitcoin` | ||
- Output: `BITCOIN: $40000` | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<title>Cryptocurrency API</title> | ||
<link rel="stylesheet" href="styles.css"> | ||
</head> | ||
<body> | ||
<div class="container"> | ||
<h1>Cryptocurrency API</h1> | ||
<input type="text" id="cryptoInput" placeholder="Enter Cryptocurrency (e.g., bitcoin)"> | ||
<button onclick="fetchCryptoData()">Get Data</button> | ||
<div id="cryptoData"></div> | ||
</div> | ||
<script src="script.js"></script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
function fetchCryptoData() { | ||
const cryptoName = document.getElementById('cryptoInput').value.toLowerCase(); | ||
const url = `https://api.coingecko.com/api/v3/simple/price?ids=${cryptoName}&vs_currencies=usd`; | ||
|
||
fetch(url) | ||
.then(response => response.json()) | ||
.then(data => { | ||
if (data[cryptoName]) { | ||
document.getElementById('cryptoData').innerHTML = ` | ||
<p><strong>${cryptoName.toUpperCase()}:</strong> $${data[cryptoName].usd}</p> | ||
`; | ||
} else { | ||
document.getElementById('cryptoData').innerHTML = `<p>Cryptocurrency not found. Please try again.</p>`; | ||
} | ||
}) | ||
.catch(error => { | ||
document.getElementById('cryptoData').innerHTML = `<p>There was an error fetching the data.</p>`; | ||
console.error('Error fetching the cryptocurrency data:', error); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
body { | ||
font-family: Arial, sans-serif; | ||
background-color: #f4f4f4; | ||
display: flex; | ||
justify-content: center; | ||
align-items: center; | ||
height: 100vh; | ||
margin: 0; | ||
} | ||
|
||
.container { | ||
text-align: center; | ||
background: #fff; | ||
padding: 30px; | ||
border-radius: 10px; | ||
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1); | ||
} | ||
|
||
h1 { | ||
margin-bottom: 20px; | ||
color: #333; | ||
} | ||
|
||
input[type="text"] { | ||
padding: 10px; | ||
font-size: 16px; | ||
width: 250px; | ||
margin-bottom: 20px; | ||
border: 1px solid #ccc; | ||
border-radius: 5px; | ||
} | ||
|
||
button { | ||
padding: 10px 20px; | ||
font-size: 16px; | ||
border: none; | ||
border-radius: 5px; | ||
background-color: #5cb85c; | ||
color: #fff; | ||
cursor: pointer; | ||
} | ||
|
||
button:hover { | ||
background-color: #4cae4c; | ||
} | ||
|
||
#cryptoData { | ||
margin-top: 20px; | ||
font-size: 18px; | ||
color: #555; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters