Monthly Salary
Programming Basics · JavaScript
TASK
Problem
Given hourly rate `rate` and worked hours `hours`, print salary.
EXAMPLE
Example
20 160
3200.0
LIMITS
Constraints
All numeric input values fit in JavaScript `Number`.
LEARN
Theory for this problem
+
### Monthly Salary
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.', 'Verify the accumulator initial value and both loop boundaries; this is where off-by-one errors most often appear.']
ANSWER
Solution
+
const fs = require('fs');
const input = fs.readFileSync(0, 'utf8').trimEnd();
let [rate, hours] = input.trim().split(/\s+/).filter(Boolean).map(Number);
let result = rate * hours;
console.log(Number.isInteger(result) ? result.toFixed(1) : result);