Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function solve(input) {
- let index = 0;
- let town = input[index++];
- let packet = input[index++];
- let vip = input[index++];
- let days = +input[index++];
- if (days >= 8) {
- days -= 1;
- }
- let sum = days * 1;
- let count = 0;
- let invalid = true;
- if (town == 'Bansko' || town == 'Borovets') {
- if (vip == 'yes') {
- switch (packet) {
- case "withEquipment":
- sum *= 100 * 0.9;
- break;
- case "noEquipment":
- sum *= 80 * 0.95;
- break;
- } count++;
- } else {
- switch (packet) {
- case "withEquipment":
- sum *= 100;
- break;
- case "noEquipment":
- sum *= 80;
- break;
- }
- } count++;
- } else if (town == 'Varna' || town == 'Burgas') {
- if (vip == 'yes') {
- switch (packet) {
- case "withBreakfast":
- sum *= 130 * 0.88;
- break;
- case "noBreakfast":
- sum *= 100 * 0.93;
- break;
- }count++;
- } else {
- switch (packet) {
- case "withBreakfast":
- sum *= 130;
- break;
- case "noBreakfast":
- sum *= 100;
- break;
- }count++;
- }
- } else {
- console.log("Invalid input!");
- invalid = false;
- }
- if (days < 1) {
- console.log("Days must be positive number!");
- } else if (invalid) {
- console.log(`The price is ${sum.toFixed(2)}lv! Have a nice time!`);
- }
- }
- solve(['Gabrovo', 'noBreakfast', 'no', '3'])
Add Comment
Please, Sign In to add comment