Advertisement
desito07

Home

Mar 1st, 2020
325
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.26 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 * 0.15);
  27. }
  28. } else if (flower == "Gladiolus") {
  29. price = 2.5;
  30. if (count < 80) {
  31. discount = -(price * 0.2);
  32. }
  33. }
  34. let totaldiscount = discount * count;
  35. let totalPrice = price * count - totaldiscount;
  36. let diff = Math.abs(totalPrice - budget);
  37. if (budget > totalPrice) {
  38. console.log(
  39. `Hey, you have a great garden with ${count} ${flower} and ${diff.toFixed(
  40. 2
  41. )} leva left.`
  42. );
  43. } else if (budget < totalPrice) {
  44. console.log(`Not enough money, you need ${diff.toFixed(2)} leva more.`);
  45. }
  46. }
  47. Home(["Roses", "55", "250"]);
  48. Home(["Tulips", "88", "260"]);
  49. Home(["Narcissus", "119", "360"]);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement