Advertisement
Spocoman

Safari

Mar 15th, 2022
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function safari(input) {
  2.     let budget = Number(input[0]);
  3.     let fuel = Number(input[1]);
  4.     let day = input[2];
  5.  
  6.     let sum = fuel * 2.1 + 100;
  7.  
  8.     if (day == "Saturday") {
  9.         sum *= 0.9;
  10.     } else {
  11.         sum *= 0.8;
  12.     }
  13.  
  14.     if (budget >= sum) {
  15.         console.log(`Safari time! Money left: ${(budget - sum).toFixed(2)} lv. `);
  16.     } else {
  17.         console.log(`Not enough money! Money needed: ${(sum - budget).toFixed(2)} lv.`);
  18.     }
  19. }
  20.  
  21. Решение с тернарен оператор:
  22.  
  23. function safari(input) {
  24.     let budget = Number(input[0]);
  25.     let fuel = Number(input[1]);
  26.     let day = input[2];
  27.  
  28.     let sum = fuel * 2.1 + 100;
  29.     sum *= day == "Saturday"? 0.9 : 0.8;
  30.    
  31.     console.log(budget >= sum? `Safari time! Money left: ${(budget - sum).toFixed(2)} lv. `
  32.                 :`Not enough money! Money needed: ${(sum - budget).toFixed(2)} lv.`);
  33. }
  34.  
  35. Тарикатско решение:)
  36.  
  37. function safari(input) {
  38.     let sum = Number(input[0]) - ((Number(input[1]) * 2.1 + 100) * (input[2] == "Saturday" ? 0.9 : 0.8));  
  39.     console.log(sum >= 0 ? `Safari time! Money left: ${sum.toFixed(2)} lv. `
  40.                 :`Not enough money! Money needed: ${Math.abs(sum).toFixed(2)} lv.`);
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement