Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function newHouse(input) {
- let flowerType = input[0];
- let quantity = Number(input[1]);
- let budget = Number(input[2]);
- let roses = 5;
- let dahlias = 3.80;
- let tulips = 2.80;
- let narcissus = 3;
- let gladiolus = 2.50;
- let totalPrice = 0;
- if (flowerType == "Roses") {
- totalPrice = quantity * roses;
- if (quantity > 80) {
- totalPrice = totalPrice - totalPrice * 10 /100;
- }
- } else if (flowerType == "Dahlias") {
- totalPrice = quantity * dahlias;
- if (quantity > 90) {
- totalPrice = totalPrice - totalPrice * 15 / 100;
- }
- } else if (flowerType == "Tulips") {
- totalPrice = quantity * tulips;
- if (quantity > 80) {
- totalPrice = quantity * tulips - (quantity * tulips) * 15 / 100;
- }
- } else if (flowerType == "Narcissus") {
- totalPrice = quantity * narcissus;
- if (quantity < 120) {
- totalPrice = totalPrice + totalPrice * 15 / 100;
- }
- } else if (flowerType == "Gladiolus") {
- totalPrice = quantity * gladiolus;
- if (quantity < 80) {
- totalPrice = totalPrice + totalPrice * 20 / 100;
- }
- }
- if (totalPrice <= budget) {
- console.log(`Hey, you have a great garden with ${quantity} ${flowerType} and ${(budget - totalPrice).toFixed(2)} leva left.`);
- } else {
- console.log(`Not enough money, you need ${(totalPrice - budget).toFixed(2)} leva more.`)
- }
- }
Add Comment
Please, Sign In to add comment