Advertisement
vborislavova

04. New House - Conditional Statements Advanced

Feb 24th, 2020
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function newHouse(input) {
  2.     let typeFlowers = input.shift();
  3.     let qtyFlowers = Number(input.shift());  
  4.     let bugdet = Number(input.shift());  
  5.  
  6.     let moneyLeft = 0;
  7.     let moneyNeeded = 0;
  8.     let totalPrice = 0;
  9.  
  10.     if (typeFlowers == "Roses") {
  11.         if (qtyFlowers > 80) {
  12.           totalPrice = (qtyFlowers * 5) * 0.9;
  13.         } else {
  14.           totalPrice = qtyFlowers * 5;
  15.         }
  16.     } else if(typeFlowers == "Dahlias") {
  17.         if (qtyFlowers > 90) {
  18.           totalPrice = (qtyFlowers * 3.80) * 0.85;
  19.         } else {
  20.           totalPrice = qtyFlowers * 3.80;
  21.         }
  22.     } else if(typeFlowers == "Tulips") {
  23.         if (qtyFlowers > 80) {
  24.           totalPrice = (qtyFlowers * 2.80) * 0.85;
  25.         } else {
  26.           totalPrice = qtyFlowers * 2.80;
  27.         }
  28.     } else if(typeFlowers == "Narcissus") {
  29.         if (qtyFlowers < 120) {
  30.           totalPrice = (qtyFlowers * 3) * 1.15;
  31.         } else {
  32.           totalPrice = qtyFlowers * 3;
  33.         }
  34.     } else if(typeFlowers == "Gladiolus") {
  35.         if (qtyFlowers < 80) {
  36.           totalPrice = (qtyFlowers * 2.50) * 1.20;
  37.         } else {
  38.           totalPrice = qtyFlowers * 2.50;
  39.         }
  40.     }
  41.  
  42.     if (bugdet >= totalPrice) {
  43.       console.log(`Hey, you have a great garden with ${qtyFlowers} ${typeFlowers} and ${(bugdet - totalPrice).toFixed(2)} leva left.`);
  44.     } else {
  45.       console.log(`Not enough money, you need ${(totalPrice - bugdet).toFixed(2)} leva more.`);
  46.     }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement