Skip to content

Commit 5d01f91

Browse files
authored
Merge pull request #39 from tajulafreen/Currcency_converter
50Projects-HTML-CSS-JavaScript : Currcency converter
2 parents b122c9c + a94bc17 commit 5d01f91

File tree

4 files changed

+119
-0
lines changed

4 files changed

+119
-0
lines changed

README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,17 @@ In order to run this project you need:
408408
</details>
409409
</li>
410410

411+
<li>
412+
<details>
413+
<summary>Currency Converter</summary>
414+
<p>This project is a Currency Converter application built using HTML, CSS, and JavaScript. It allows users to convert one currency into another by inputting an amount and selecting the currencies they want to convert from and to.</p>
415+
<ul>
416+
<li><a href="https://tajulafreen.github.io/50Projects-HTML-CSS-JavaScript/Source-Code/CurrencyConverter/">Live Demo</a></li>
417+
<li><a href="https://github.com/tajulafreen/50Projects-HTML-CSS-JavaScript/tree/main/Source-Code/CurrencyConverter">Source</a></li>
418+
</ul>
419+
</details>
420+
</li>
421+
411422
</ol>
412423

413424
<p align="right">(<a href="#readme-top">back to top</a>)</p>
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
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+
<title>Currency Converter</title>
7+
<link rel="stylesheet" href="style.css">
8+
</head>
9+
<body>
10+
<div class="container">
11+
<h1>Currency Converter</h1>
12+
<div class="converter">
13+
<input type="number" id="amount" placeholder="Amount" />
14+
<select id="from-currency">
15+
<option value="USD">USD</option>
16+
<option value="EUR">EUR</option>
17+
<option value="INR">INR</option>
18+
<option value="GBP">GBP</option>
19+
</select>
20+
<span>to</span>
21+
<select id="to-currency">
22+
<option value="INR">INR</option>
23+
<option value="USD">USD</option>
24+
<option value="EUR">EUR</option>
25+
<option value="GBP">GBP</option>
26+
</select>
27+
<button id="convert">Convert</button>
28+
</div>
29+
<div id="result"></div>
30+
</div>
31+
<script src="script.js"></script>
32+
</body>
33+
</html>
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
document.getElementById('convert').addEventListener('click', () => {
2+
const amount = document.getElementById('amount').value;
3+
const fromCurrency = document.getElementById('from-currency').value;
4+
const toCurrency = document.getElementById('to-currency').value;
5+
6+
if (amount === '' || Number.isNaN(Number(amount))) {
7+
alert('Please enter a valid amount');
8+
return;
9+
}
10+
11+
const apiUrl = `https://api.exchangerate-api.com/v4/latest/${fromCurrency}`;
12+
13+
fetch(apiUrl)
14+
.then((response) => response.json())
15+
.then((data) => {
16+
const exchangeRate = data.rates[toCurrency];
17+
const convertedAmount = (amount * exchangeRate).toFixed(2);
18+
document.getElementById(
19+
'result',
20+
).innerText = `${amount} ${fromCurrency} = ${convertedAmount} ${toCurrency}`;
21+
})
22+
.catch((error) => {
23+
document.getElementById(
24+
'result',
25+
).innerText = `Error fetching exchange rates. ${error}Try again later.`;
26+
});
27+
});
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
body {
2+
font-family: Arial, sans-serif;
3+
background-color: #f4f4f4;
4+
margin: 0;
5+
padding: 0;
6+
display: flex;
7+
justify-content: center;
8+
align-items: center;
9+
height: 100vh;
10+
}
11+
12+
.container {
13+
background-color: white;
14+
padding: 20px;
15+
border-radius: 10px;
16+
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
17+
width: 400px;
18+
text-align: center;
19+
}
20+
21+
h1 {
22+
margin-bottom: 20px;
23+
}
24+
25+
input,
26+
select,
27+
button {
28+
margin: 10px 0;
29+
padding: 10px;
30+
font-size: 16px;
31+
}
32+
33+
button {
34+
background-color: #4caf50;
35+
color: white;
36+
border: none;
37+
cursor: pointer;
38+
}
39+
40+
button:hover {
41+
background-color: #45a049;
42+
}
43+
44+
#result {
45+
margin-top: 20px;
46+
font-size: 18px;
47+
font-weight: bold;
48+
}

0 commit comments

Comments
 (0)