Join codinglabsolution for an engaging tutorial on expanding your JavaScript skills through project-building. Today, we'll delve into creating a 'Currency Converter', a fun and straightforward project requiring HTML, CSS, and JavaScript.
Video Tutorial:
Project Folder Structure:
Let’s build the project folder structure before we begin writing the code. We create a project folder called ‘Currency Converter’. Inside this folder, we have index.html, style.css, script.js, currency-codes.js, API-key.js, and SVG icon files.
HTML:
We begin with the HTML Code. First, create a file called – ‘index.html’. Copy the code below and paste it into your HTML file.
CSS:
Next, we style our list using CSS. For this copy, the code provided to you below and paste it into your stylesheet.
Javascript:
"Next, let's incorporate functionality using JavaScript. Copy the code below and paste it into your script file.
Firstly, store the API key in 'api-key.js' and all currency codes in 'currency-codes.js'.
Then, follow these implementation steps:
1. Initialize HTML references and store the API URL in a variable.
2. Populate dropdown options with currency codes.
3. When the user clicks 'Convert' or when the page loads, call the 'convertCurrency' function.
4. Within 'convertCurrency', capture the user's dropdown selections or use default values.
5. If the user hasn't submitted a blank amount, make a GET request to the API URL using the 'fetch' method.
6. The API returns current rates for each currency.
7. Convert the entered amount to another currency using the fetched rate, displaying it up to two decimals."
"Feel free to personalize the project according to your preferences. For any questions, suggestions, or feedback, please leave a comment below. You can download the complete source code by clicking the 'Download Code' button below."