Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function truckDrivers(input) {
- let season = input[0];
- let km = Number(input[1]);
- let sum = 0;
- if (km > 0 && km <= 5000) {
- switch (season) {
- case 'Spring':
- case 'Autumn':
- sum = 0.75;
- break;
- case 'Summer':
- sum = 0.9;
- break;
- case 'Winter':
- sum = 1.05;
- break;
- }
- } else if (km > 5000 && km <= 10000) {
- switch (season) {
- case 'Spring':
- case 'Autumn':
- sum = 0.95;
- break;
- case 'Summer':
- sum = 1.1;
- break;
- case 'Winter':
- sum = 1.25;
- break;
- }
- } else if (km > 10000 && km <= 20000) {
- sum = 1.45;
- }
- console.log(`${(sum * km * 4 * 0.9).toFixed(2)}`);
- }
- Решение с тернарен оператор:
- function truckDrivers(input) {
- let season = input[0];
- let km = Number(input[1]);
- let sum =
- (km <= 5000 ? (season === 'Summer' ? 0.9 : season === 'Winter' ? 1.05 : 0.75) :
- km <= 10000 ? (season === 'Summer' ? 1.1 : season === 'Winter' ? 1.25 : 0.95) :
- km <= 20000 ? 1.45 : 1) * km * 4 * 0.9;
- console.log(`${sum.toFixed(2)}`);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement