Build a Currency Converter using HTML, CSS & JavaScript π±
π± Build a Currency Converter using HTML, CSS & JavaScript
Hello everyone π
Welcome back!
In this beginner-friendly project, we will build a Currency Converter using HTML, CSS & JavaScript π»
This project helps you learn:
- API Integration
- Fetch API
- Async/Await
- DOM Manipulation
- Real-world JavaScript Development
Perfect for beginners π
---
π Features of Currency Converter
✔ Convert currencies instantly
✔ Real-time exchange rates
✔ User-friendly interface
✔ Responsive design
✔ Beginner-friendly project
---
π§± Step 1: HTML Code
HTML
<!DOCTYPE html>
<html>
<head>
<title>Currency Converter</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<div class="container">
<h1>Currency Converter</h1>
<input type="number"
id="amount"
placeholder="Enter Amount">
<select id="from">
<option value="USD">USD</option>
<option value="INR">INR</option>
<option value="EUR">EUR</option>
</select>
<select id="to">
<option value="INR">INR</option>
<option value="USD">USD</option>
<option value="EUR">EUR</option>
</select>
<button onclick="convertCurrency()">
Convert
</button>
<h2 id="result"></h2>
</div>
<script src="script.js"></script>
</body>
</html>
---
π¨ Step 2: CSS Code
CSS
*{
margin:0;
padding:0;
box-sizing:border-box;
font-family:Arial;
}
body{
height:100vh;
display:flex;
justify-content:center;
align-items:center;
background:linear-gradient(135deg,#4e54c8,#8f94fb);
}
.container{
background:white;
padding:30px;
width:400px;
border-radius:15px;
text-align:center;
box-shadow:0 10px 25px rgba(0,0,0,0.2);
}
input,select{
width:100%;
padding:12px;
margin:10px 0;
border:2px solid #ddd;
border-radius:8px;
}
button{
width:100%;
padding:12px;
border:none;
border-radius:8px;
background:#007bff;
color:white;
cursor:pointer;
}
#result{
margin-top:20px;
}
---
⚡ Step 3: JavaScript Code
JavaScript
async function convertCurrency(){
const amount =
document.getElementById("amount").value;
const from =
document.getElementById("from").value;
const to =
document.getElementById("to").value;
const url =
`https://api.exchangerate-api.com/v4/latest/${from}`;
const response = await fetch(url);
const data = await response.json();
const rate = data.rates[to];
const result = amount * rate;
document.getElementById("result")
.innerText =
`${amount} ${from} = ${result.toFixed(2)} ${to}`;
}
---
π― What You Will Learn
✅ API Integration
✅ Fetch API
✅ Async/Await
✅ Currency Conversion Logic
✅ DOM Manipulation
---
⭐ Tips to Improve Project
π Add country flags π
π Add swap currency button π
π Show exchange rates π
π Add dark mode π
---
π Conclusion
This was a Currency Converter Project using JavaScript π±
A perfect beginner-to-intermediate project to improve your API and JavaScript skills π
---
π’ Also Read
π Weather App Project
π Expense Tracker Project
π Password Generator Project
---
π Save and share this project π
π Follow for more coding content π»
Comments
Post a Comment