Home > Web Front-end > JS Tutorial > How to calculate and print bonus and total using base salary via JavaScript?

How to calculate and print bonus and total using base salary via JavaScript?

PHPz
Release: 2023-08-24 18:57:01
forward
723 people have browsed it

We first multiply the base salary by a certain percentage to determine the bonus ratio. Next, we multiply the bonus percentage by the base salary to calculate the bonus amount. Finally, we add the bonus amount to the base salary to determine the total salary and print all three values.

Here is an example of how to calculate and print bonus and total salary using base salary in JavaScript -

// Declare basic salary variable
var basicSalary = 5000;

// Calculate bonus (10% of basic salary)
var bonus = basicSalary * 0.1;

// Calculate gross salary (basic salary + bonus)
var grossSalary = basicSalary + bonus;

// Print the values
console.log("Basic Salary: " + basicSalary);
console.log("Bonus: " + bonus);
console.log("Gross Salary: " + grossSalary);
Copy after login

illustrate

  • The first line declares a variable basicSalary and assigns it a value of 5000.

  • The second line uses the * operator to calculate the bonus by multiplying the value of basicSalary by 0.1 (10% of base salary).

  • The third line calculates the total salary by adding the values ​​of basicSalary and bonus using the operator.

  • The next few lines use the console.log() method to print the values ​​of basicSalary, bonus and grossSalary.

NOTE - The above code snippet is a minimal working example, in a real-life scenario you should use validation, error handling and user input to get salary, bonus percentage and other relevant details. p>

Output

How to calculate and print bonus and total using base salary via JavaScript?

The above is the detailed content of How to calculate and print bonus and total using base salary via JavaScript?. For more information, please follow other related articles on the PHP Chinese website!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template