Advertisement
Guest User

Untitled

a guest
Mar 29th, 2020
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solve(flowerType, count, budget) {
  2.     count = Number(count);
  3.     budget = Number(budget);
  4.     let spent = 0;
  5.    
  6.     if (flowerType === "Roses") {
  7.         spent = count * 5;
  8.         if (count > 80) {
  9.             spent = spent * 0.9;
  10.         }
  11.     } else if (flowerType === "Dahlias") {
  12.         spent = count * 3.80;
  13.         if (count > 90) {
  14.             spent = spent * 0.85;
  15.         }
  16.     } else if (flowerType === "Tulips") {
  17.         spent = count * 2.80;
  18.         if (count > 80) {
  19.             spent = spent * 0.85;
  20.         }
  21.     } else if (flowerType === "Narcissus") {
  22.         spent = count * 3;
  23.         if (count < 120) {
  24.             spent = spent * 1.15;
  25.         }
  26.     } else if (flowerType === "Gladiolus") {
  27.         spent = count * 2.5;
  28.         if (count < 80) {
  29.             spent = spent * 1.20;
  30.         }
  31.     }
  32.     if (budget > spent) {
  33.         console.log(`Hey, you have a great garden with ${count} ${flowerType} and ${(budget - spent).toFixed(2)} leva left.`)
  34.     } else {
  35.         console.log(`Not enough money, you need ${(spent - budget).toFixed(2)} leva more.`)
  36.     }
  37. }
  38. solve ("Narcissus", 119, 360);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement