Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function skiTrip(input) {
- let daysToStay = Number(input.shift());
- let typeOfRoom = input.shift();
- let rating = input.shift();
- let stayPrice = 0;
- let discount = 0;
- let discountRate = 0;
- if (typeOfRoom == "room for one person") {
- stayPrice = (daysToStay - 1) * 18.00;
- if (rating == "positive"){
- discountRate = stayPrice + (stayPrice * 0.25);
- console.log(discountRate.toFixed(2));
- } else {
- discountRate = stayPrice - (stayPrice * 0.10);
- console.log(discountRate.toFixed(2));
- }
- } else if (typeOfRoom == "apartment") {
- stayPrice = (daysToStay - 1) * 25.00;
- if (daysToStay < 10) {
- discount = stayPrice - (stayPrice * 0.30);
- if (rating == "positive"){
- discountRate = discount + (discount * 0.25);
- console.log(discountRate.toFixed(2));
- } else {
- discountRate = discount - (discount * 0.10);
- console.log(discountRate.toFixed(2));
- }
- } else if (daysToStay >= 10 && daysToStay <= 15) {
- discount = stayPrice - (stayPrice * 0.35);
- if (rating == "positive"){
- discountRate = discount + (discount * 0.25);
- console.log(discountRate.toFixed(2));
- } else {
- discountRate = discount - (discount * 0.10);
- console.log(discountRate.toFixed(2));
- }
- } else {
- discount = stayPrice - (stayPrice * 0.50);
- if (rating == "positive"){
- discountRate = discount + (discount * 0.25);
- console.log(discountRate.toFixed(2));
- } else {
- discountRate = discount - (discount * 0.10);
- console.log(discountRate.toFixed(2));
- }
- }
- } else if (typeOfRoom == "president apartment") {
- stayPrice = (daysToStay - 1) * 35.00;
- if (daysToStay < 10) {
- discount = stayPrice - (stayPrice * 0.10);
- if (rating == "positive"){
- discountRate = discount + (discount * 0.25);
- console.log(discountRate.toFixed(2));
- } else {
- discountRate = discount - (discount * 0.10);
- console.log(discountRate.toFixed(2));
- }
- } else if (daysToStay >= 10 && daysToStay <= 15) {
- discount = stayPrice - (stayPrice * 0.15);
- if (rating == "positive"){
- discountRate = discount + (discount * 0.25);
- console.log(discountRate.toFixed(2));
- } else {
- discountRate = discount - (discount * 0.10);
- console.log(discountRate.toFixed(2));
- }
- } else {
- discount = stayPrice - (stayPrice * 0.20);
- if (rating == "positive"){
- discountRate = discount + (discount * 0.25);
- console.log(discountRate.toFixed(2));
- } else {
- discountRate = discount - (discount * 0.10);
- console.log(discountRate.toFixed(2));
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement