PROBLEM 68
Medium

Store Discount System

Programming Basics · JavaScript

</>
STATUS Not solved

TASK

Problem

#68

Given purchase `amount`: 0% below 1000, 5% from 1000 to below 5000, 10% from 5000 upward. Print final price.

EXAMPLE

Example

Input
6000
Output
5400.0

LIMITS

Constraints

All numeric input values fit in JavaScript `Number`.
📖
LEARN Theory for this problem
+

### Store Discount System

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.', 'Build the final state of the data structure first, then convert it to the required output order.']

ANSWER Solution
+
const fs = require('fs');
const input = fs.readFileSync(0, 'utf8').trimEnd();
let a = Number(input);
if (a >= 5000) {
    a *= 0.9;
} else {
    if (a >= 1000) {
        a *= 0.95;
    }
}
console.log(Number.isInteger(a) ? a.toFixed(1) : a);