Advertisement
Guest User

baking

a guest
Feb 27th, 2020
215
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solve(input) {
  2.     let numberOfParticipant = Number(input.shift());
  3.    
  4.     let counterAll = 0;
  5.     let forCharity = 0;
  6.  
  7.     for (let i = 1; i <= numberOfParticipant; i++) {
  8.         let name = input.shift();
  9.         let type = input.shift();
  10.  
  11.         let pаrticipantCookies = 0;
  12.         let participantCakes = 0;
  13.         let participentWaffles = 0;
  14.  
  15.         while (type !== "Stop baking!") {
  16.             let numberOftype = Number(input.shift());
  17.            
  18.             counterAll += numberOftype
  19.  
  20.             if (type === "cookies") {
  21.                 pаrticipantCookies += numberOftype;
  22.             }
  23.             else if (type === "cakes") {
  24.                 participantCakes += numberOftype;
  25.             }
  26.             else if (type === "waffles") {
  27.                 participentWaffles += numberOftype;
  28.             }
  29.  
  30.             type = input.shift();
  31.  
  32.             if (type == "Stop baking!"){
  33.                 console.log(`${name} baked ${pаrticipantCookies} cookies, ${participantCakes} cakes and ${participentWaffles} waffles.`)
  34.                 forCharity += pаrticipantCookies * 1.50 + participantCakes * 7.80 + participentWaffles * 2.30
  35.             }
  36.         }
  37.     }
  38.     console.log(`All bakery sold: ${counterAll}`)
  39.     console.log(`Total sum for charity: ${forCharity.toFixed(2)} lv.`)
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement