desito07

New House

Feb 29th, 2020
226
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.25 KB | None | 0 0
  1. function Home(input) {
  2. let flower = input.shift();
  3. let count = Number(input.shift());
  4. let budget = Number(input.shift());
  5. let price = 0;
  6. let discount = 0;
  7.  
  8. if (flower == "Roses") {
  9. price = 5;
  10. if (count > 80) {
  11. discount = price * 0.1;
  12. }
  13. } else if (flower == "Dahlias") {
  14. price = 3.8;
  15. if (count > 90) {
  16. discount = price * 0.15;
  17. }
  18. } else if (flower == "Tulips") {
  19. price = 2.8;
  20. if (count > 80) {
  21. discount = price * 0.15;
  22. }
  23. } else if (flower == "Narcissus") {
  24. price = 3;
  25. if (count < 120) {
  26. discount = price - price * 1.15;
  27. }
  28. } else if (flower == "Gladiolus") {
  29. price = 2.5;
  30. if (count < 80) {
  31. discount = price - price * 1.2;
  32. }
  33. }
  34. let totalPrice = price * count;
  35. let totalDiscount = discount * count;
  36. let expense = totalPrice - totalDiscount;
  37. let diff = expense - budget;
  38. if (budget > expense) {
  39. console.log(
  40. `Hey, you have a great garden with ${count} ${flower} and ${(
  41. budget - expense
  42. ).toFixed(2)} leva left.`
  43. );
  44. } else if (budget < expense) {
  45. console.log(
  46. `Not enough money, you need ${Math.abs(diff).toFixed(2)} leva more.`
  47. );
  48. }
  49. }
  50. Home(["Narcissus", "119", "360"]);
Advertisement
Add Comment
Please, Sign In to add comment