Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*Cozonacs - 06.03.2021 mid Exam*/
- function cozonacs(input) {
- let [budget, priceFlkg] = input.map(Number);
- let priceEggsPack = 0.75 * priceFlkg;
- let priceMilk250 = (1.25 * priceFlkg) / 4;
- let priceCoz = priceEggsPack + priceMilk250 + priceFlkg;
- let countCoz = parseInt(budget / priceCoz);
- let moneyleft = budget - (countCoz * priceCoz);
- let takedEggs = 0;
- for (let i = 1; i <= countCoz; i++) {
- if (i % 3 == 0) {
- takedEggs += i - 2;
- }
- }
- let counteggs = countCoz * 3 - takedEggs;
- console.log(`You made ${countCoz} cozonacs! Now you have ${counteggs} eggs and ${moneyleft.toFixed(2)}BGN left.`);
- }
- cozonacs(['20.50', '1.25']); // => You made 7 cozonacs! Now you have 16 eggs and 2.45BGN left.
- cozonacs(['15.75', '1.4']); // => You made 5 cozonacs! Now you have 14 eggs and 1.31BGN left.
- /*
- Create a program that calculates how much cozonacs you can make with the budget you have. First, you will receive your budget. Then, you will receive the price for 1 kg flour. Here is the recipe for one cozonac:
- Eggs 1 pack
- Flour 1 kg
- Milk 0.2501
- The price for 1 pack of eggs is 75% of the price for 1 kg flour. The price for 11 milk is 25% more than price for 1 kg flour. Notice, that you need 0.2501 milk for one cozonac and the calculated price is for 11.
- Start cooking the cozonacs and keep making them until you have enough budget. Keep in mind that:
- • For every cozonac that you make, you will receive 3 colored eggs.
- • For every 3rd cozonac that you make, you will lose some of your colored eggs after you have received the usual 3 colored eggs for your cozonac. The count of eggs you will lose is calculated when you subtract 2 from your current count of cozonacs - ({currentCozonacsCount } - 2)
- In the end, print the cozonacs you made, the eggs you have gathered and the money you have left, formatted to the 2nd decimal place, in the following format:
- "You made {countOfCozonacs} cozonacs! Now you have {coloredEggs} eggs and {moneyLeft}BGN left . "
- Input / Constraints
- • On the 1s! line you will receive the budget - a real number in the range [0.0_100000.0]
- • On the 2nd line you will receive the price for 1 kg flour - a real number in the range [0.0_100000.0]
- • The input will always be in the right format.
- • You will always have a remaining budget.
- • There will not be a case in which the eggs become a negative count.
- Output
- • Money formatted to the 2nd decimal place in the format described above.
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement