Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function transportPrice(input) {
- let km = Number(input[0]);
- let time = input[1];
- let price = 0;
- if (km < 20) {
- if (time == "day") {
- price = km * 0.79 + 0.7;
- } else {
- price = km * 0.9 + 0.7;
- }
- } else if (km >= 100) {
- price = km * 0.06;
- }else {
- price = km * 0.09;
- }
- console.log(`${price.toFixed(2)}`);
- }
- РЕШЕНИЕ С ТЕРНАРЕН ОПЕРАТОР:
- function transportPrice(input) {
- let km = Number(input[0]);
- let time = input[1];
- let price = km < 20 ? km * (time == "day" ? 0.79 : 0.9) + 0.7 : km >= 100 ? km * 0.06 : km * 0.09;
- console.log(`${price.toFixed(2)}`);
- }
- Или леко тарикатската:
- function transportPrice(input) {
- let km = Number(input[0]);
- console.log(`${(km < 20 ? km * (input[1] == "day" ? 0.79 : 0.9) + 0.7 : km >= 100 ? km * 0.06 : km * 0.09).toFixed(2)}`);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement