Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,34 @@ <h1>tanh</h1>
<h1>=</h1>
</button>
</div>


<div class="currency-converter">
<h3>Currency Converter</h3>
<input type="number" id="amount" placeholder="Enter amount">
<select id="fromCurrency">
<option value="USD">USD - US Dollar</option>
<option value="INR">INR - Indian Rupee</option>
<option value="EUR">EUR - Euro</option>
<option value="GBP">GBP - British Pound</option>
<option value="JPY">JPY - Japanese Yen</option>
<option value="AUD">AUD - Australian Dollar</option>
<option value="CAD">CAD - Canadian Dollar</option>
</select>
<select id="toCurrency">
<option value="USD">USD - US Dollar</option>
<option value="INR">INR - Indian Rupee</option>
<option value="EUR">EUR - Euro</option>
<option value="GBP">GBP - British Pound</option>
<option value="JPY">JPY - Japanese Yen</option>
<option value="AUD">AUD - Australian Dollar</option>
<option value="CAD">CAD - Canadian Dollar</option>
</select>
<button onclick="convertCurrency()">Convert</button>
<p id="convertedAmount"></p>
</div>


<div class="historyDisplay">
<h2>HISTORY</h2>
<table id="tableParent"></table>
Expand Down
29 changes: 29 additions & 0 deletions script.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,35 @@ function solveQuadratic() {
}
}

function convertCurrency() {
const amount = parseFloat(document.getElementById("amount").value);
const fromCurrency = document.getElementById("fromCurrency").value;
const toCurrency = document.getElementById("toCurrency").value;
const resultElement = document.getElementById("convertedAmount");

if (isNaN(amount) || amount <= 0) {
alert("Please enter a valid amount.");
return;
}
const rates = {
USD: 1,
INR: 83.0,
EUR: 0.92,
GBP: 0.79,
JPY: 146.2,
AUD: 1.55,
CAD: 1.35
};


const amountInUSD = amount / rates[fromCurrency];
const convertedValue = amountInUSD * rates[toCurrency];

resultElement.textContent = `${convertedValue.toFixed(2)} ${toCurrency}`;
}



Copy link

Copilot AI Aug 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hardcoded exchange rates will become outdated quickly and provide inaccurate conversions. Consider using a live exchange rate API or at minimum add comments indicating when these rates were last updated.

Suggested change
async function convertCurrency() {
const amount = parseFloat(document.getElementById("amount").value);
const fromCurrency = document.getElementById("fromCurrency").value;
const toCurrency = document.getElementById("toCurrency").value;
const resultElement = document.getElementById("convertedAmount");
if (isNaN(amount) || amount <= 0) {
alert("Please enter a valid amount.");
return;
}
try {
// Fetch live exchange rates from exchangerate.host
const response = await fetch(`https://api.exchangerate.host/latest?base=${fromCurrency}&symbols=${toCurrency}`);
if (!response.ok) {
throw new Error("Failed to fetch exchange rates.");
}
const data = await response.json();
const rate = data.rates[toCurrency];
if (!rate) {
throw new Error("Invalid currency code.");
}
const convertedValue = amount * rate;
resultElement.textContent = `${convertedValue.toFixed(2)} ${toCurrency}`;
} catch (error) {
resultElement.textContent = "Error converting currency.";
console.error(error);
}
}

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok I'll modify it

function solveCubic(p, q) {
const D = (q * q) / 4 + (p * p * p) / 27;
if (D > 0) {
Expand Down
73 changes: 73 additions & 0 deletions style.css
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,79 @@
--primary-calculator-shadow: #ff5f72;
}

.currency-converter {
background-color: #fff;
border: 1px solid indianred;
border-radius: 8px;
padding: 16px;
max-width: 350px;
margin: 20px auto;
box-shadow: 0px 4px 8px rgba(0, 0, 0, 0.1);
font-family: sans-serif;
}

.currency-converter h3 {
color: indianred;
text-align: center;
margin-bottom: 14px;
}

.currency-converter input,
.currency-converter select {
width: 100%;
padding: 10px;
margin: 6px 0;
border: 1px solid #ccc;
border-radius: 6px;
font-size: 1rem;
box-sizing: border-box;
}

.currency-converter button {
width: 100%;
background-color: indianred;
color: white;
border: none;
padding: 10px;
font-size: 1rem;
border-radius: 6px;
cursor: pointer;
margin-top: 10px;
transition: background-color 0.2s ease;
}

.currency-converter button:hover {
background-color: #E57373;
}

.currency-converter p {
text-align: center;
margin-top: 12px;
font-size: 1.1rem;
color: #333;
font-weight: bold;
}

@media (max-width: 576px) {
.currency-converter {
padding: 12px;
max-width: 90%;
}
.currency-converter h3 {
font-size: 1.2rem;
}
.currency-converter input,
.currency-converter select,
.currency-converter button {
font-size: 0.95rem;
padding: 8px;
}
}





.html {
scroll-behavior: smooth;
}
Expand Down