Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function solve(overnights, type, rating) {
- overnights = Number(overnights) - 1;
- const accomodationTypes = {
- 'room for one person': {
- price: 18,
- discount: [0,0,0]
- },
- 'apartment': {
- price: 25,
- discount: [0.3, 0.35, 0.5]
- },
- 'president apartment': {
- price: 35,
- discount: [0.1, 0.15, 0.2]
- }
- };
- let finalPrice;
- if (overnights < 10) {
- finalPrice = accomodationTypes[type].price * overnights;
- finalPrice -= finalPrice * accomodationTypes[type].discount[0];
- } else if (overnights >= 10 && overnights <= 15) {
- finalPrice = accomodationTypes[type].price * overnights;
- finalPrice -= finalPrice * accomodationTypes[type].discount[1];
- } else if (overnights > 15) {
- finalPrice = accomodationTypes[type].price * overnights;
- finalPrice -= finalPrice * accomodationTypes[type].discount[2];
- }
- if(rating == 'positive') {
- finalPrice *= 1.25;
- } else if (rating == 'negative') {
- finalPrice *= 0.9;
- }
- console.log(finalPrice.toFixed(2));
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement