This project is a web-based currency converter. It allows users to select currencies, input an amount, and get the converted amount in another currency. The project uses the ExchangeRate-API for fetching current exchange rates.
- Currency Selection: Users can choose from a wide range of currencies for both source and destination.
- Real-time Conversion: The conversion happens in real-time as the user types in the amount.
- Swap Feature: A convenient swap button to quickly exchange source and destination currencies.
- Error Handling: The application handles errors gracefully, particularly in fetching data from the API.
- Responsive Design: Styled with CSS for a pleasant user experience across various devices.
- A modern web browser.
- Internet access to fetch exchange rates from the ExchangeRate-API.
- Clone the repository or download the source code.
- Open the
index.html
file in a web browser.
This application uses the ExchangeRate-API to fetch real-time currency exchange rates. Ensure that you have access to the API and replace the API key in the fetch URL if necessary.
- Select Currencies: Choose the source and destination currencies from the dropdown menus.
- Enter Amount: Type in the amount you want to convert.
- View Result: The converted amount is displayed automatically.
- Swap Currencies: Click the swap button if you wish to change the direction of conversion.
The main HTML elements include:
- Two
<select>
elements for choosing source and destination currencies. - An
<input>
for entering the amount. - A
<div>
to display the result. - A
<button>
to swap the currencies.
The provided CSS styles:
- Ensure a clean, minimalist layout centered on the page.
- Style the input fields, select menus, and button for a cohesive look and feel.
- Include hover and focus states for better user interaction.
The JavaScript code:
- Fetches and populates currency data on DOMContentLoaded.
- Handles user inputs and performs currency conversion.
- Implements a swap functionality for easy toggling between source and destination currencies.
Errors, particularly in fetching data from the API, are handled gracefully with error messages logged to the console.
Note: Replace the API key in the fetch URL with your own key from ExchangeRate-API for the application to work properly.