Friday, September 27, 2024
Google search engine
HomeLanguagesJavascriptHow to calculate and print bonus and gross using basic salary by...

How to calculate and print bonus and gross using basic salary by JavaScript ?

In this article, we will learn how to create a JavaScript program that will ask the user to enter their basic salary and then calculate the bonus amount which will be 20% of their basic salary or base pay. The gross salary is the bonus amount + basic salary.

bonus amount = 20% of basic salary
gross salary = bonus amount + basic salary

Approach: In this code, we will be displaying an input box to the user which will prompt the user to enter the basic pay. On clicking the submit button, the calculate function is called which computes the bonus amount and the gross amount and displays it to the user using the DOM elements in JavaScript.

Examples:

Input 1: 50000
Output:
Bonus: 10000
Gross: 60000

Input 2: 2500
Output:
Bonus: 500
Gross: 3000

Input 3: 32500
Output:
Bonus: 6500
Gross: 39000

Below is the implementation of the above approach. 

Javascript




<script>
    (function calculate() {
        var bpay, bonus, gross;
        bpay = 50000;
     
        //bonus is 20% of basic salary
        bonus = 0.2 * bpay;
        gross = bonus + bpay;
     
        console.log("Basic Pay: " + bpay);
        console.log("Bonus: " + bonus);
        console.log("Gross: " + gross);
    })();
</script>


Output:

Basic Pay: 50000
Bonus: 10000
Gross: 60000
Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, neveropen Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!

RELATED ARTICLES

Most Popular

Recent Comments