Added new function of currency converter#169
Added new function of currency converter#169adityakankal2004 wants to merge 1 commit intoDhanushNehru:mainfrom
Conversation
Signed-off-by: aditya kankal <adityabuisness12@gmail.com>
✅ Deploy Preview for calculator-dhanushnehru ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
|
Hey should i modify my changes |
There was a problem hiding this comment.
Pull Request Overview
This PR adds a currency converter feature to an existing calculator application, providing users with the ability to convert between different currencies alongside the existing calculator functionality.
- Adds a new currency converter component with support for 7 major currencies (USD, INR, EUR, GBP, JPY, AUD, CAD)
- Implements conversion logic using hardcoded exchange rates with USD as the base currency
- Integrates the converter into the existing UI with responsive styling that matches the application's design
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| style.css | Adds comprehensive styling for the currency converter component including responsive design for mobile devices |
| script.js | Implements the convertCurrency() function with hardcoded exchange rates and validation logic |
| index.html | Integrates the currency converter UI elements into the existing calculator interface |
Comments suppressed due to low confidence (1)
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
You can also share your feedback on Copilot code review for a chance to win a $100 gift card. Take the survey.
| } | ||
|
|
||
|
|
||
|
|
There was a problem hiding this comment.
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.
| 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); | |
| } | |
| } | |
Currency convert with your stylish calculator looks good.