Advertisement
TZinovieva

The Biscuit Factory JS Fundamentals Mid Exam

Feb 21st, 2023
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function theBiscuitFactory(arr) {
  2.     let biscuitsPerDay = Number(arr.shift());
  3.     let workersCount = Number(arr.shift());
  4.     let competingFactoryProduction = Number(arr.shift());
  5.    
  6.     let biscuitsProduced = 0;
  7.    
  8.     for (let day = 1; day <= 30; day++) {
  9.       let biscuitsDailyProduction = biscuitsPerDay * workersCount;
  10.       if (day % 3 === 0) {
  11.         biscuitsDailyProduction *= 0.75;
  12.       }
  13.       biscuitsProduced += Math.floor(biscuitsDailyProduction);
  14.     }
  15.    
  16.     console.log(`You have produced ${biscuitsProduced} biscuits for the past month.`);
  17.    
  18.     let percentage = ((biscuitsProduced - competingFactoryProduction) / competingFactoryProduction) * 100;
  19.     if (percentage > 0) {
  20.       console.log(`You produce ${percentage.toFixed(2)} percent more biscuits.`);
  21.     } else {
  22.       console.log(`You produce ${Math.abs(percentage).toFixed(2)} percent less biscuits.`);
  23.     }
  24.   }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement