Purchase Cost
Programming Basics · JavaScript
TASK
Problem
Given integer item price `price` and quantity `count`, print the total cost.
EXAMPLE
Example
120 4
480
LIMITS
Constraints
All numeric input values fit in JavaScript `Number`.
LEARN
Theory for this problem
+
### Purchase Cost
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.', 'Consider a repeated key or value: the data structure must update exactly as required by the statement.']
ANSWER
Solution
+
const fs = require('fs');
const input = fs.readFileSync(0, 'utf8').trimEnd();
let [price, count] = input.trim().split(/\s+/).filter(Boolean).map(Number);
let result = price * count;
console.log(result);