-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExercise03.NewHouse.js
More file actions
28 lines (22 loc) · 1.08 KB
/
Exercise03.NewHouse.js
File metadata and controls
28 lines (22 loc) · 1.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
function newHouse(flowerType, flowerCount, budget){
let pricePerFlower = 0;
switch (flowerType) {
case `Roses`: pricePerFlower = 5; break;
case `Dahlias`: pricePerFlower = 3.80; break;
case `Tulips`: pricePerFlower = 2.80; break;
case `Narcissus`: pricePerFlower = 3; break;
case `Gladiolus`: pricePerFlower = 2.50; break;
}
let total = pricePerFlower * flowerCount;
if (flowerType === `Roses` && flowerCount > 80) total *= 0.90;
if (flowerType === `Dahlias` && flowerCount > 90) total *= 0.85;
if (flowerType === `Tulips` && flowerCount > 80) total *= 0.85;
if (flowerType === `Narcissus` && flowerCount < 120) total *= 1.15;
if (flowerType === `Gladiolus` && flowerCount < 80) total *= 1.20;
if (budget >= total){
console.log(`Hey, you have a great garden with ${flowerCount} ${flowerType} and ${(budget - total).toFixed(2)} leva left.`);
} else {
console.log(`Not enough money, you need ${(total - budget).toFixed(2)} leva more.`);
}
}
newHouse("Tulips", 88, 260);