Here's a simple example of a currency exchange calculator using HTML, CSS, and JavaScript. You can embed this code in an HTML file and open it in a web browser to use the calculator.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Currency Exchange Calculator</title>
<style>
body {
font-family: Arial, sans-serif;
background-color: #f4f4f4;
text-align: center;
margin: 0;
padding: 0;
}
#calculator {
max-width: 400px;
margin: 50px auto;
background-color: #fff;
padding: 20px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
border-radius: 8px;
}
input {
width: 100%;
padding: 10px;
margin-bottom: 15px;
box-sizing: border-box;
}
button {
background-color: #4caf50;
color: #fff;
padding: 10px;
border: none;
border-radius: 5px;
cursor: pointer;
}
button:hover {
background-color: #45a049;
}
#result {
font-size: 18px;
font-weight: bold;
margin-top: 20px;
}
</style>
</head>
<body>
<div id="calculator">
<h2>Currency Exchange Calculator</h2>
<label for="amount">Amount:</label>
<input type="number" id="amount" placeholder="Enter amount" step="0.01">
<label for="fromCurrency">From Currency:</label>
<select id="fromCurrency">
<option value="USD">USD</option>
<option value="EUR">EUR</option>
<!-- Add more currency options as needed -->
</select>
<label for="toCurrency">To Currency:</label>
<select id="toCurrency">
<option value="USD">USD</option>
<option value="EUR">EUR</option>
<!-- Add more currency options as needed -->
</select>
<button onclick="convertCurrency()">Convert</button>
<div id="result"></div>
</div>
<script>
function convertCurrency() {
const amount = document.getElementById('amount').value;
const fromCurrency = document.getElementById('fromCurrency').value;
const toCurrency = document.getElementById('toCurrency').value;
// You can use a real API for currency conversion here
// For simplicity, let's assume a fixed conversion rate for this example
const conversionRate = 1.2; // Change this with the actual conversion rate
const result = (amount * conversionRate).toFixed(2);
document.getElementById('result').innerHTML = `${amount} ${fromCurrency} is ${result} ${toCurrency}`;
}
</script>
</body>
</html>