LearnFrenzy
Sign in Take a free test

Operators · Operators Coding Problems · Question 4

Salary slip with compound assignment in JavaScript Solution, output & explanation

  • Program
  • Easy
  • 0 comments
  • Answer explained
  • Moderated community
Question 4 Back to Exercise

Starting from a basic salary of ₹40,000, add 20% HRA and 12% DA, subtract ₹1,800 PF and 10% tax on the gross, using compound assignment operators.

Solution
main.js
const basic = 40000;
let salary = basic;

salary += basic * 0.20;      // HRA
salary += basic * 0.12;      // DA
const gross = salary;
salary -= 1800;              // PF
salary -= gross * 0.10;      // tax on the gross

console.log(`Basic: ${basic}`);
console.log(`Gross: ${gross}`);
console.log(`Net:   ${salary}`);

Output Verified by running it on Node.js

Basic: 40000
Gross: 52800
Net:   45720

Gross = 40000 + 8000 + 4800 = 52800. Net = 52800 − 1800 − 5280 = 45720. x += y is shorthand for x = x + y.

Discussion & Comments 0

Share your method, a shortcut, or ask about a step you didn't follow.

No comments yet. Be the first to share your solution!

Post your comment

Comments appear after a quick review by our team.

Search LearnFrenzy

Esc

Quick links