Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // 03. New House
- function solve(arg) {
- let flowerType = arg[0];
- let flowersCount = Number(arg[1]);
- let budget = Number(arg[2]);
- let unitPrice = 0;
- switch(flowerType) {
- case "Roses":
- unitPrice = 5;
- break;
- case "Dahlias":
- unitPrice = 3.80;
- break;
- case "Tulips":
- unitPrice = 2.80;
- break;
- case "Narcissus":
- unitPrice = 3;
- break;
- case "Gladiolus":
- unitPrice = 2.50;
- break;
- default:
- // unitPrice = ;
- break;
- }
- let totalPrice = flowersCount * unitPrice;
- if (flowerType === "Roses" && flowersCount > 80) {
- totalPrice *= 0.9;
- } else if (flowerType === "Dahlias" && flowersCount > 90) {
- totalPrice *= 0.85;
- } else if (flowerType === "Tulips" && flowersCount > 80) {
- totalPrice *= 0.85;
- } else if (flowerType === "Narcissus" && flowersCount < 120) {
- totalPrice *= 1.15;
- } else if (flowerType === "Gladiolus" && flowersCount < 80) {
- totalPrice *= 1.20;
- }
- let amountLeft = budget - totalPrice;
- if (amountLeft >= 0) {
- console.log(`Hey, you have a great garden with ${flowersCount} ${flowerType} and ${amountLeft.toFixed(2)} leva left.`)
- } else {
- console.log(`Not enough money, you need ${Math.abs(amountLeft).toFixed(2)} leva more.`)
- }
- }
- solve(["Tulips", "88", "260"]) ;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement