Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function fuelTank(input) {
- let fuel = input[0]
- let liters = Number(input[1])
- let cart = input[2]
- let literPrice = 0
- if (fuel == 'Gas') {
- if (cart == 'Yes') {
- literPrice = 0.85;
- } else {
- literPrice = 0.93;
- }
- } else if (fuel == 'Diesel') {
- if (cart == 'Yes') {
- literPrice = 2.21;
- } else {
- literPrice = 2.33;
- }
- } else if (fuel == 'Gasoline') {
- if (cart == 'Yes') {
- literPrice = 2.04;
- } else {
- literPrice = 2.22;
- }
- }
- if (liters >= 20 && liters <= 25) {
- literPrice *= 0.92;
- } else if (liters > 25) {
- literPrice *= 0.9;
- }
- console.log(`${(literPrice * liters).toFixed(2)} lv.`)
- }
- Второ решение с тернарен оператор:
- function fuelTank(input) {
- let fuel = input[0]
- let liters = Number(input[1])
- let cart = input[2]
- let literPrice =
- fuel == 'Gas' ? (cart == 'Yes' ? 0.85 : 0.93) :
- fuel == 'Diesel' ? (cart == 'Yes' ? 2.21 : 2.33) :
- fuel == 'Gasoline' ? (cart == 'Yes' ? 2.04 : 2.22) : 0;
- literPrice *= liters >= 20 && liters <= 25 ? 0.92 : liters > 25 ? 0.9 : 1;
- console.log(`${(literPrice * liters).toFixed(2)} lv.`)
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement