Skip to content

Commit cb1e32f

Browse files
authored
Merge pull request #876 from malivinayak/currencyConverter/malivinayak
Real-time Currency Conversion with Styling Enhancements
2 parents 3b3820c + 2363c29 commit cb1e32f

File tree

3 files changed

+125
-0
lines changed

3 files changed

+125
-0
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
6+
<link rel="stylesheet" href="styles.css">
7+
<title>Currency Converter</title>
8+
</head>
9+
<body>
10+
<div class="converter">
11+
<h2>Currency Converter</h2>
12+
<div class="input-container">
13+
<label for="amount">Amount:</label>
14+
<input type="number" id="amount" placeholder="Enter amount">
15+
</div>
16+
<div class="input-container">
17+
<label for="fromCurrency">From:</label>
18+
<select id="fromCurrency"></select>
19+
</div>
20+
<div class="input-container">
21+
<label for="toCurrency">To:</label>
22+
<select id="toCurrency"></select>
23+
</div>
24+
<button onclick="convert()">Convert</button>
25+
<h3>Result: <span id="result">0.00</span></h3>
26+
</div>
27+
<script src="https://openexchangerates.org/api/latest.json?app_id=YOUR_API_KEY&callback=initCurrencies"></script>
28+
<script src="script.js"></script>
29+
</body>
30+
</html>
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
let currencies;
2+
const apiKey = 'YOUR_API_KEY'; // Replace with your API key
3+
4+
function initCurrencies(data) {
5+
currencies = Object.keys(data.rates);
6+
7+
// Populate currency dropdowns
8+
const fromCurrencyDropdown = document.getElementById('fromCurrency');
9+
const toCurrencyDropdown = document.getElementById('toCurrency');
10+
11+
currencies.forEach(currency => {
12+
const option = document.createElement('option');
13+
option.value = currency;
14+
option.text = currency;
15+
fromCurrencyDropdown.add(option);
16+
17+
const optionTo = document.createElement('option');
18+
optionTo.value = currency;
19+
optionTo.text = currency;
20+
toCurrencyDropdown.add(optionTo);
21+
});
22+
}
23+
24+
function convert() {
25+
const amount = parseFloat(document.getElementById('amount').value);
26+
const fromCurrency = document.getElementById('fromCurrency').value;
27+
const toCurrency = document.getElementById('toCurrency').value;
28+
29+
fetch(`https://openexchangerates.org/api/convert/${amount}?from=${fromCurrency}&to=${toCurrency}&app_id=${apiKey}`)
30+
.then(response => response.json())
31+
.then(data => {
32+
const convertedAmount = data.result;
33+
document.getElementById('result').innerText = convertedAmount.toFixed(2);
34+
})
35+
.catch(error => console.error('Error:', error));
36+
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
body {
2+
font-family: 'Arial', sans-serif;
3+
display: flex;
4+
align-items: center;
5+
justify-content: center;
6+
height: 100vh;
7+
margin: 0;
8+
background: linear-gradient(135deg, #3498db, #8e44ad, #e74c3c, #f39c12);
9+
background-size: 400% 400%;
10+
animation: gradientAnimation 15s infinite;
11+
}
12+
13+
@keyframes gradientAnimation {
14+
0% {
15+
background-position: 0% 50%;
16+
}
17+
50% {
18+
background-position: 100% 50%;
19+
}
20+
100% {
21+
background-position: 0% 50%;
22+
}
23+
}
24+
25+
.converter {
26+
text-align: center;
27+
border: 1px solid #ccc;
28+
padding: 20px;
29+
border-radius: 8px;
30+
background: rgba(255, 255, 255, 0.9);
31+
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
32+
}
33+
34+
.input-container {
35+
margin: 10px 0;
36+
}
37+
38+
input, select, button {
39+
padding: 10px;
40+
margin: 5px;
41+
border: 1px solid #ddd;
42+
border-radius: 4px;
43+
box-sizing: border-box;
44+
}
45+
46+
button {
47+
background: linear-gradient(45deg, #3498db, #8e44ad, #e74c3c, #f39c12);
48+
color: white;
49+
cursor: pointer;
50+
border: none;
51+
border-radius: 4px;
52+
padding: 10px 20px;
53+
font-size: 1em;
54+
transition: background 0.3s ease;
55+
}
56+
57+
button:hover {
58+
background: linear-gradient(45deg, #f39c12, #e74c3c, #8e44ad, #3498db);
59+
}

0 commit comments

Comments
 (0)