-
Notifications
You must be signed in to change notification settings - Fork 0
/
price.js
39 lines (23 loc) · 918 Bytes
/
price.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
checkPrice = {};
//checking if price is a number and a valid positive integer
var isNumber = function (num){
return typeof num === "number" && num > 0;
};
//itemPriceWithTax1 returns a boolean here
checkPrice.itemPriceWithTax1 = function (potentialPrice , taxRate, callBack) {
if (typeof callBack !== "function") return callBack(false, 'Error');
var res1 = isNumber(potentialPrice, taxRate);
var res2 = (potentialPrice * taxRate) + potentialPrice;
if (res1 && res2) {
callBack(true, null);
} else {
callBack(false, 'error, enter a valid whole number')
}
};
//itemPriceWithTax2 returns the computed values here
checkPrice.itemPriceWithTax2 = function (potentialPrice , taxRate) {
var res1 = isNumber(potentialPrice, taxRate);
var res2 = (potentialPrice * taxRate) + potentialPrice;
return res1 && res2;
};
module.exports = checkPrice;