Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function newHouse(input) {
- let type = input.shift();
- let flowers = Number(input.shift());
- let budget = Number(input.shift());
- let price = 0;
- let discount = 0;
- if (type == "Roses") {
- if (flowers > 80) {
- discount = (flowers * 5.00) * 0.1;
- price = (flowers * 5.00) - discount;
- } else {
- price = flowers * 5.00;
- }
- } else if (type == "Dahlias") {
- if (flowers > 90) {
- discount = (flowers * 3.80) * 0.15;
- price = (flowers * 3.80) - discount;
- } else {
- price = flowers * 3.80;
- }
- } else if (type == "Tulips") {
- if (flowers > 80) {
- discount = (flowers * 2.80) * 0.15;
- price = (flowers * 2.80) - discount;
- } else {
- price = flowers * 2.80;
- }
- } else if (type == "Narcissus") {
- if (flowers < 120) {
- discount = (flowers * 3) * 0.15;
- price = (flowers * 3) + discount;
- } else {
- price = flowers * 3;
- }
- } else if (type == "Gladiolus") {
- if (flowers < 80) {
- discount = (flowers * 2.50) * 0.20;
- price = (flowers * 2.50) + discount;
- } else {
- price = flowers * 2.50;
- }
- }
- if (budget >= price) {
- console.log(`Hey, you have a great garden with ${flowers} ${type} and ${(budget - price).toFixed(2)} leva left.`);
- } else {
- console.log(`Not enough money, you need ${(price - budget).toFixed(2)} leva more.`);
- }
- }
- newHouse(["Narcissus", 119, 360]);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement