Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function bakingCompetition(input) {
- let bakers = Number(input[0]);
- let index = 1, totalSweets = 0, totalSum = 0;
- for (let i = 0; i < bakers; i++) {
- let baker = "";
- let cookies = 0, cakes = 0, waffles = 0;
- while (true) {
- let command = input[index++];
- if (command == "Stop baking!") {
- break;
- }
- if (baker == "") {
- baker = command;
- } else {
- let sweet = command;
- let sweetCount = Number(input[index++]);
- if (sweet == "cookies") {
- cookies += sweetCount;
- } else if (sweet == "cakes") {
- cakes += sweetCount;
- } else {
- waffles += sweetCount;
- }
- totalSweets += sweetCount;
- }
- }
- totalSum += 1.50 * cookies + 7.80 * cakes + 2.30 * waffles;
- console.log(`${baker} baked ${cookies} cookies, ${cakes} cakes and ${waffles} waffles.`);
- }
- console.log(`All bakery sold: ${totalSweets}\nTotal sum for charity: ${totalSum.toFixed(2)} lv.`);
- return;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement