Loan Calculator using JavaScript
Hello Guys! In this blog, I'm going to explain to you how to create Loan calculator using JavaScript. This will be a step-by-step guide including HTML and CSS. Let's get started 🚀.
Let's cover the HTML part
HTML is a markup language. We use HTML to make the skeleton of a website.
Now let's import the font awesome CDN in our HTML head tag. fontawesome is a library that is used for icons in a website.
Now let's import the fonts using Google Fonts API. Below is the code for Poppins Font. Paste the below code in head tag.
Now let's design the container in our <body> tag. In the below HTML code, we have created a container that contains the <h1> tag for the heading. Then form-input div which has inputs that are loan amount, percentage, interest rate, and months of repayment.
Next we have calculate button which have onclick attribute with calculateLoan() function
Here is the Final HTML Code
Output Till Now
Let's understand CSS Part
In the below CSS code,
- We declare a * selectors to set the font Poppins that we have imported in our head tag.
- Next we declare a body selector which consists of styles for dark mode and aligns all elements in the body to the center.
- Next we have container with border deepskyblue and border-radius for curve edges to improve UI.
Output Till Now
Finally a JavaScript Part
In the below javascript code, we have calculateLoan() arrow function.
In calculateLoan() function we have declared 3 variables that are amount, interest, and months and then grab their respective values from the input. Next, we have monthlyPayment, totalInterest and totalPayment variable with a formula to calculate. Next, we set the result using DOM Manipulation.