-
Notifications
You must be signed in to change notification settings - Fork 0
/
oilPrice.js
22 lines (20 loc) · 887 Bytes
/
oilPrice.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
function oilPrice(dieselQuantity, petrolQuantity, octaneQuantity) {
if (dieselQuantity < 0 || petrolQuantity < 0 || octaneQuantity < 0 || typeof dieselQuantity !== 'number' || typeof petrolQuantity !== 'number' || typeof octaneQuantity !== 'number') {
return 'Enter a positive integer number.';
}
else {
const dieselPrice = 114;
const petrolPrice = 130;
const octanePrice = 135;
const totalDieselPrice = dieselQuantity * dieselPrice;
const totalPetrolPrice = petrolQuantity * petrolPrice;
const totalOctanePrice = octaneQuantity * octanePrice;
return totalDieselPrice + totalPetrolPrice + totalOctanePrice;
}
}
console.log(oilPrice(1, 0, 0));
console.log(oilPrice(0, 1, 0));
console.log(oilPrice(0, 0, 1));
console.log(oilPrice(1, 1, 1));
console.log(oilPrice(-1, 1, 1));
console.log(oilPrice(1, 1, '1'));