Advertisement
StefanShivarov

06. Mine

Jul 25th, 2021
956
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function zad3(input){
  2.  
  3.     let counter = 0;
  4.    
  5.     for(let i = 0; i < Number(input[0]); i++){
  6.  
  7.  
  8.         let expectedAvgDaily = Number(input[++counter]);
  9.         let days = Number(input[++counter]);
  10.         let actualAvgDaily = 0;
  11.  
  12.         for(let j = 0; j < days; j++){
  13.  
  14.             actualAvgDaily += Number(input[++counter]);
  15.  
  16.         }
  17.  
  18.         actualAvgDaily /= days;
  19.  
  20.         if(actualAvgDaily >= expectedAvgDaily){
  21.  
  22.             console.log(`Good job! Average gold per day: ${actualAvgDaily.toFixed(2)}.`);
  23.         }else{
  24.             console.log(`You need ${(expectedAvgDaily - actualAvgDaily).toFixed(2)} gold.`);
  25.         }
  26.     }
  27.  
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement