Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function matchTickets(input) {
- let budget = Number(input[0]);
- let category = input[1];
- let people = Number(input[2]);
- if (people <= 4) {
- budget *= 0.25;
- } else if (people <= 9) {
- budget *= 0.4;
- } else if (people <= 24) {
- budget *= 0.5;
- } else if (people < 50) {
- budget *= 0.6;
- } else {
- budget *= 0.75;
- }
- if (category === "VIP") {
- budget -= 499.99 * people;
- } else {
- budget -= 249.99 * people;
- }
- if (budget >= 0) {
- console.log(`Yes! You have ${budget.toFixed(2)} leva left.`);
- } else {
- console.log(`Not enough money! You need ${Math.abs(budget).toFixed(2)} leva.`);
- }
- }
- Решение с тернарен оператор:
- function matchTickets(input) {
- let budget = Number(input[0]);
- let category = input[1];
- let people = Number(input[2]);
- budget *=
- people <= 4 ? 0.25 :
- people <= 9 ? 0.4 :
- people <= 24 ? 0.5 :
- people < 50 ? 0.6 : 0.75;
- budget -= (category === "VIP" ? 499.99 : 249.99) * people;
- console.log(budget >= 0 ? `Yes! You have ${budget.toFixed(2)} leva left.`
- : `Not enough money! You need ${Math.abs(budget).toFixed(2)} leva.`);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement