Advertisement
gskorchev

new house

Jan 29th, 2019
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function newHouse(input) {
  2.     let type = input.shift();
  3.     let flowers = Number(input.shift());
  4.     let budget = Number(input.shift());
  5.     let price = 0;
  6.     let discount = 0;
  7.     if (type == "Roses") {
  8.         if (flowers > 80) {
  9.             discount = (flowers * 5.00) * 0.1;
  10.             price = (flowers * 5.00) - discount;
  11.         } else {
  12.             price = flowers * 5.00;
  13.         }
  14.     } else if (type == "Dahlias") {
  15.         if (flowers > 90) {
  16.             discount = (flowers * 3.80) * 0.15;
  17.             price = (flowers * 3.80) - discount;
  18.         } else {
  19.             price = flowers * 3.80;
  20.         }
  21.     } else if (type == "Tulips") {
  22.         if (flowers > 80) {
  23.             discount = (flowers * 2.80) * 0.15;
  24.             price = (flowers * 2.80) - discount;
  25.         } else {
  26.             price = flowers * 2.80;
  27.         }
  28.     } else if (type == "Narcissus") {
  29.         if (flowers < 120) {
  30.             discount = (flowers * 3) * 0.15;
  31.             price = (flowers * 3) + discount;
  32.         } else {
  33.             price = flowers * 3;
  34.         }
  35.     } else if (type == "Gladiolus") {
  36.         if (flowers < 80) {
  37.             discount = (flowers * 2.50) * 0.20;
  38.             price = (flowers * 2.50) + discount;
  39.         } else {
  40.             price = flowers * 2.50;
  41.         }
  42.     }
  43.     if (budget >= price) {
  44.         console.log(`Hey, you have a great garden with ${flowers} ${type} and ${(budget - price).toFixed(2)} leva left.`);
  45.     } else {
  46.         console.log(`Not enough money, you need ${(price - budget).toFixed(2)} leva more.`);
  47.     }
  48. }
  49. newHouse(["Narcissus", 119, 360]);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement