Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function theMandalorian(input) {
- let period = input[0] ;
- let nights = Number(input[1]) ;
- let priceStudio = 0 ;
- let priceApartment = 0 ;
- let discountStudio = 0 ;
- let discountApartment = 0 ;
- // Determine total cost of stay per property type for every month
- switch (period) {
- case "May":
- case "October": priceStudio = nights * 50.00 ; priceApartment = nights * 65.00 ; break ;
- case "June":
- case "September": priceStudio = nights * 75.20 ; priceApartment = nights * 68.70 ; break ;
- case "July":
- case "August": priceStudio = nights * 76.00 ; priceApartment = nights * 77.00 ; break ;
- }
- // Determine discounts for Studio
- if (period === "May" || period === "October") {
- if (nights > 14) {
- discountStudio = 30/100 ;
- } else if (nights > 7) {
- discountStudio = 5/100 ;
- } else {
- discountStudio = 0 ;
- }
- } else if (period === "June" || period === "September") {
- if (nights > 14) {
- discountStudio = 20/100 ;
- } else {
- discountStudio = 0 ;
- }
- }
- // Determine discounts for Apartment
- if (nights > 14) {
- discountApartment = 10/100 ;
- } else {
- discountApartment = 0 ;
- }
- let priceStudioDiscounted = priceStudio * (1 - discountStudio) ;
- let priceApartmentDiscounted = priceApartment * (1 - discountApartment) ;
- console.log(`Apartment: ${priceApartmentDiscounted.toFixed(2)} lv.`) ;
- console.log(`Studio: ${priceStudioDiscounted.toFixed(2)} lv.`) ;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement