Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function safari(input) {
- let budget = Number(input[0]);
- let fuel = Number(input[1]);
- let day = input[2];
- let sum = fuel * 2.1 + 100;
- if (day == "Saturday") {
- sum *= 0.9;
- } else {
- sum *= 0.8;
- }
- if (budget >= sum) {
- console.log(`Safari time! Money left: ${(budget - sum).toFixed(2)} lv. `);
- } else {
- console.log(`Not enough money! Money needed: ${(sum - budget).toFixed(2)} lv.`);
- }
- }
- Решение с тернарен оператор:
- function safari(input) {
- let budget = Number(input[0]);
- let fuel = Number(input[1]);
- let day = input[2];
- let sum = fuel * 2.1 + 100;
- sum *= day == "Saturday"? 0.9 : 0.8;
- console.log(budget >= sum? `Safari time! Money left: ${(budget - sum).toFixed(2)} lv. `
- :`Not enough money! Money needed: ${(sum - budget).toFixed(2)} lv.`);
- }
- Тарикатско решение:)
- function safari(input) {
- let sum = Number(input[0]) - ((Number(input[1]) * 2.1 + 100) * (input[2] == "Saturday" ? 0.9 : 0.8));
- console.log(sum >= 0 ? `Safari time! Money left: ${sum.toFixed(2)} lv. `
- :`Not enough money! Money needed: ${Math.abs(sum).toFixed(2)} lv.`);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement