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

Popular posts from this blog

Build a Simple Calculator using HTML, CSS & JavaScript (Beginner Project)

Top 10 Python Programs for Beginners (Easy + Practical Guide)

JavaScript Notes for Beginners (Simple + Easy Guide) ⚡