Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function solve(input) {
- let numberOfParticipant = Number(input.shift());
- let counterAll = 0;
- let forCharity = 0;
- for (let i = 1; i <= numberOfParticipant; i++) {
- let name = input.shift();
- let type = input.shift();
- let pаrticipantCookies = 0;
- let participantCakes = 0;
- let participentWaffles = 0;
- while (type !== "Stop baking!") {
- let numberOftype = Number(input.shift());
- counterAll += numberOftype
- if (type === "cookies") {
- pаrticipantCookies += numberOftype;
- }
- else if (type === "cakes") {
- participantCakes += numberOftype;
- }
- else if (type === "waffles") {
- participentWaffles += numberOftype;
- }
- type = input.shift();
- if (type == "Stop baking!"){
- console.log(`${name} baked ${pаrticipantCookies} cookies, ${participantCakes} cakes and ${participentWaffles} waffles.`)
- forCharity += pаrticipantCookies * 1.50 + participantCakes * 7.80 + participentWaffles * 2.30
- }
- }
- }
- console.log(`All bakery sold: ${counterAll}`)
- console.log(`Total sum for charity: ${forCharity.toFixed(2)} lv.`)
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement