Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function vacantion(input) {
- let budget = Number(input[0]);
- let season = input[1];
- let location = '';
- let place = '';
- if (season === 'Summer') {
- location = 'Alaska';
- } else {
- location = 'Morocco';
- }
- if (budget > 3000) {
- place = 'Hotel';
- budget *= 0.9;
- } else if (budget > 1000) {
- if (season === 'Summer') {
- budget *= 0.8;
- } else {
- budget *= 0.6;
- }
- place = 'Hut';
- } else if (budget > 0) {
- if (season === 'Summer') {
- budget *= 0.65;
- } else {
- budget *= 0.45;
- }
- place = 'Camp';
- }
- console.log(`${location} - ${place} - ${budget.toFixed(2)}`);
- }
- Решение с тернарен оператор:
- function vacantion(input) {
- let budget = Number(input[0]);
- let season = input[1];
- let location = season === 'Summer' ? 'Alaska' : 'Morocco';
- let place =
- budget > 3000 ? 'Hotel' :
- budget > 1000 ? 'Hut' : 'Camp';
- budget *=
- budget > 3000 ? 0.9 :
- budget > 1000 ? (season === 'Summer' ? 0.8 : 0.6) :
- (season === 'Summer' ? 0.65 : 0.45);
- console.log(`${location} - ${place} - ${budget.toFixed(2)}`);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement