Salary After Tax
Programming Basics · JavaScript
TASK
Problem
Given salary `salary` and tax percent `tax`, print take-home amount.
EXAMPLE
Example
5000 13
4350.0
LIMITS
Constraints
salary ≥ 0; 0 ≤ tax ≤ 100
LEARN
Theory for this problem
+
### Salary After Tax
JavaScript arithmetic works with numeric values stored in variables. A clear solution reads the needed values, computes the formula with `+`, `-`, `*`, `/` or `**`, and prints only the final result.
NEED HELP?
Hints
+
['Write the formula using named intermediate values if it contains more than one operation.', 'After each iteration, it should be clear what has already been accumulated and what remains to be processed.']
ANSWER
Solution
+
const fs = require('fs');
const input = fs.readFileSync(0, 'utf8').trimEnd();
let [salary, tax] = input.trim().split(/\s+/).filter(Boolean).map(Number);
let result = (((salary) * (100 - tax)) / 100);
console.log(Number.isInteger(result) ? result.toFixed(1) : result);