Advertisement
Spocoman

Cake Tycoon

Oct 11th, 2023 (edited)
904
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function cakeTycoon(input) {
  2.     let plannedCakes = Number(input[0]);
  3.     let cakeFlour = Number(input[1]);
  4.     let flourAvailable = Number(input[2]);
  5.     let truffleCount = Number(input[3]);
  6.     let trufflePrice = Number(input[4]);
  7.  
  8.     let cakes = parseInt(flourAvailable / cakeFlour);
  9.  
  10.     if (cakes >= plannedCakes) {
  11.         let cakePrice = truffleCount * trufflePrice / plannedCakes * 1.25;
  12.         console.log(`All products available, price of a cake: ${cakePrice.toFixed(2)}`);
  13.     } else {
  14.         let flourNeeded = plannedCakes * cakeFlour - flourAvailable;
  15.         console.log(`Can make only ${cakes} cakes, need ${flourNeeded.toFixed(2)} kg more flour`);
  16.     }
  17.  
  18.     return;
  19. }
  20.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement