Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function schoolCamp(input) {
- let season = input[0];
- let group = input[1];
- let people = Number(input[2]);
- let nights = Number(input[3]);
- let price = 0;
- let sport = '';
- if (season === 'Winter') {
- switch (group) {
- case 'boys':
- price = 9.60;
- sport = 'Judo';
- break;
- case 'girls':
- price = 9.60;
- sport = 'Gymnastics';
- break;
- case 'mixed':
- price = 10.00;
- sport = 'Ski';
- break;
- }
- } else if (season === 'Spring') {
- switch (group) {
- case 'boys':
- price = 7.20;
- sport = 'Tennis';
- break;
- case 'girls':
- price = 7.20;
- sport = 'Athletics';
- break;
- case 'mixed':
- price = 9.50;
- sport = 'Cycling';
- break;
- }
- } else {
- switch (group) {
- case 'boys':
- price = 15.00;
- sport = 'Football';
- break;
- case 'girls':
- price = 15.00;
- sport = 'Volleyball';
- break;
- case 'mixed':
- price = 20.00;
- sport = 'Swimming';
- break;
- }
- }
- if (people >= 50) {
- price *= 0.50;
- } else if (people >= 20) {
- price *= 0.85;
- } else if (people >= 10) {
- price *= 0.95;
- }
- let total = price * people * nights;
- console.log(`${sport} ${total.toFixed(2)} lv.`);
- }
- Решение с тернарен оператор:
- function schoolCamp(input) {
- let season = input[0];
- let group = input[1];
- let people = Number(input[2]);
- let nights = Number(input[3]);
- let price = 0;
- let sport = '';
- if (season === 'Winter') {
- price = group === 'boys' ? 9.60 : group === 'girls' ? 9.60 : 10.00;
- sport = group === 'boys' ? 'Judo' : group === 'girls' ? 'Gymnastics' : 'Ski';
- } else if (season === 'Spring') {
- price = group === 'boys' ? 7.20 : group === 'girls' ? 7.20 : 9.50;
- sport = group === 'boys' ? 'Tennis' : group === 'girls' ? 'Athletics' : 'Cycling';
- } else {
- price = group === 'boys' ? 15.00 : group === 'girls' ? 15.00 : 20.00;
- sport = group === 'boys' ? 'Football' : group === 'girls' ? 'Volleyball' : 'Swimming';
- }
- price *=
- people >= 50 ? 0.50 :
- people >= 20 ? 0.85 :
- people >= 10 ? 0.95 : 1;
- let total = price * people * nights;
- console.log(`${sport} ${total.toFixed(2)} lv.`);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement