Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function familyTrip(input) {
- let budget = Number(input[0]);
- let overnight = Number(input[1]);
- let overnightPrice = Number(input[2]);
- let additionalCosts = Number(input[3]);
- if (overnight > 7) {
- overnightPrice *= 0.95;
- }
- let totalPrice = overnight * overnightPrice + additionalCosts * budget / 100;
- if (totalPrice > budget) {
- console.log(`${(totalPrice - budget).toFixed(2)} leva needed.`);
- } else {
- console.log(`Ivanovi will be left with ${(budget - totalPrice).toFixed(2)} leva after vacation.`);
- }
- }
- РЕШЕНИЕ С ТЕРНАРЕН ОПЕРАТОР:
- function familyTrip(input) {
- let budget = Number(input[0]);
- let overnight = Number(input[1]);
- let overnightPrice = Number(input[2]);
- let additionalCosts = Number(input[3]);
- budget -= overnight * (overnight > 7 ? 0.95 : 1) * overnightPrice + (additionalCosts * budget) / 100;
- console.log(
- budget < 0 ?
- `${Math.abs(budget).toFixed(2)} leva needed.` :
- `Ivanovi will be left with ${budget.toFixed(2)} leva after vacation.`
- );
- }
Add Comment
Please, Sign In to add comment