TZinovieva

New House JS 100/100

May 20th, 2022 (edited)
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function newHouse(input) {
  2.     let flowerType = input[0];
  3.     let quantity = Number(input[1]);
  4.     let budget = Number(input[2]);
  5.  
  6.     let roses = 5;
  7.     let dahlias = 3.80;
  8.     let tulips = 2.80;
  9.     let narcissus = 3;
  10.     let gladiolus = 2.50;
  11.    
  12.     let totalPrice = 0;
  13.     if (flowerType == "Roses") {
  14.         totalPrice = quantity * roses;
  15.         if (quantity > 80) {
  16.             totalPrice = totalPrice - totalPrice * 10 /100;
  17.         }
  18.     } else if (flowerType == "Dahlias") {
  19.         totalPrice = quantity * dahlias;
  20.         if (quantity > 90) {
  21.             totalPrice = totalPrice - totalPrice * 15 / 100;
  22.         }
  23.     } else if (flowerType == "Tulips") {
  24.         totalPrice = quantity * tulips;
  25.         if (quantity > 80) {
  26.             totalPrice = quantity * tulips - (quantity * tulips) * 15 / 100;
  27.         }
  28.     } else if (flowerType == "Narcissus") {
  29.         totalPrice = quantity * narcissus;
  30.         if (quantity < 120) {
  31.             totalPrice = totalPrice + totalPrice * 15 / 100;
  32.         }
  33.     } else if (flowerType == "Gladiolus") {
  34.         totalPrice = quantity * gladiolus;
  35.         if (quantity < 80) {
  36.             totalPrice = totalPrice + totalPrice * 20 / 100;
  37.         }
  38.     }
  39.     if (totalPrice <= budget) {
  40.         console.log(`Hey, you have a great garden with ${quantity} ${flowerType} and ${(budget - totalPrice).toFixed(2)} leva left.`);
  41.     } else {
  42.         console.log(`Not enough money, you need ${(totalPrice - budget).toFixed(2)} leva more.`)
  43.     }
  44. }
Add Comment
Please, Sign In to add comment