Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function Home(input) {
- let flower = input.shift();
- let count = Number(input.shift());
- let budget = Number(input.shift());
- let price = 0;
- let discount = 0;
- if (flower == "Roses") {
- price = 5;
- if (count > 80) {
- discount = price * 0.1;
- }
- } else if (flower == "Dahlias") {
- price = 3.8;
- if (count > 90) {
- discount = price * 0.15;
- }
- } else if (flower == "Tulips") {
- price = 2.8;
- if (count > 80) {
- discount = price * 0.15;
- }
- } else if (flower == "Narcissus") {
- price = 3;
- if (count < 120) {
- discount = price - price * 1.15;
- }
- } else if (flower == "Gladiolus") {
- price = 2.5;
- if (count < 80) {
- discount = price - price * 1.2;
- }
- }
- let totalPrice = price * count;
- let totalDiscount = discount * count;
- let expense = totalPrice - totalDiscount;
- let diff = expense - budget;
- if (budget > expense) {
- console.log(
- `Hey, you have a great garden with ${count} ${flower} and ${(
- budget - expense
- ).toFixed(2)} leva left.`
- );
- } else if (budget < expense) {
- console.log(
- `Not enough money, you need ${Math.abs(diff).toFixed(2)} leva more.`
- );
- }
- }
- Home(["Narcissus", "119", "360"]);
Advertisement
Add Comment
Please, Sign In to add comment