dpeeva

Cooking Masterclass

Jun 26th, 2022 (edited)
180
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solve(input) {
  2.     const budget = Number(input[0])
  3.     const students = Number(input[1])
  4.     const price = {
  5.         flour: Number(input[2]),
  6.         eggs: Number(input[3]) * 10,
  7.         apron: Number(input[4])
  8.     }
  9.  
  10.     const flour = (students - Math.floor(students / 5)) * price.flour
  11.     const eggs = students * price.eggs
  12.     const apron = Math.ceil(students + students * 0.2) * price.apron
  13.  
  14.     const total = flour + eggs + apron
  15.  
  16.     if (budget >= total) {
  17.         console.log(`Items purchased for ${total.toFixed(2)}$`)
  18.     } else {
  19.         console.log(`${(total - budget).toFixed(2)}$ more needed.`)
  20.     }
  21. }
  22.  
  23. solve([50, 2, 1.0, 0.1, 10.0]) // Items purchased for 34.00$
  24. solve([100, 25, 4.0, 1.0, 6.0]) // 410.00$ more needed.
  25. solve([946, 20, 12.05, 0.42, 27.89]) // 0.16$ more needed.
Add Comment
Please, Sign In to add comment