<!DOCTYPE html>
<html>
<head>
<title>Currency Exchange</title>
<style>
body {
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
}
.container {
margin: 20px;
padding: 20px;
border: 1px solid #ccc;
width: 300px;
text-align: center;
}
.form-group {
margin-bottom: 10px;
}
.input-field {
width: 100%;
padding: 5px;
}
.result {
font-weight: bold;
}
.conversion-rate {
margin-top: 10px;
color: #888;
}
</style>
</head>
<body>
<div class="container">
<h2>Currency Exchange</h2>
<form id="exchangeForm">
<div class="form-group">
<label for="nairaInput">NGN (Naira)</label>
<input type="number" id="nairaInput" class="input-field" placeholder="Enter amount in NGN">
</div>
<div class="form-group">
<label for="mpesaInput">KSH (M-Pesa)</label>
<input type="number" id="mpesaInput" class="input-field" placeholder="Enter amount in KSH">
</div>
</form>
<div class="result">
<p>Converted Amount:</p>
<p id="convertedAmount"></p>
</div>
<div class="conversion-rate">
<p>Conversion Rates:</p>
<p id="ngnToKshRate"></p>
<p id="kshToNgnRate"></p>
</div>
</div>
<script>
const nairaInput = document.getElementById('nairaInput');
const mpesaInput = document.getElementById('mpesaInput');
const convertedAmount = document.getElementById('convertedAmount');
const ngnToKshRate = document.getElementById('ngnToKshRate');
const kshToNgnRate = document.getElementById('kshToNgnRate');
const ngnToKsh = 0.184907;
const kshToNgn = 5.4103;
nairaInput.addEventListener('input', convertNgnToKsh);
mpesaInput.addEventListener('input', convertKshToNgn);
function convertNgnToKsh() {
const nairaAmount = parseFloat(nairaInput.value);
const kshAmount = nairaAmount * ngnToKsh;
mpesaInput.value = kshAmount.toFixed(2);
}
function convertKshToNgn() {
const kshAmount = parseFloat(mpesaInput.value);
const nairaAmount = kshAmount * kshToNgn;
nairaInput.value = nairaAmount.toFixed(2);
}
window.addEventListener('load', function() {
ngnToKshRate.textContent = `1 NGN = ${ngnToKsh.toFixed(4)} KSH`;
kshToNgnRate.textContent = `1 KSH = ${kshToNgn.toFixed(4)} NGN`;
});
</script>
</body>
</html>