borisova936935

Untitled

Nov 21st, 2021
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function exam (input){
  2.  
  3.     let locations = Number(input[0]);
  4.     let index = 1;
  5.     for(let i = 1; i <= locations; i++) {
  6.         let avrAmount = 0;
  7.         let expectedAmount = Number(input[index]);
  8.         index++;
  9.         let days = Number(input[index]);
  10.         index++;
  11.         for(let n = 1; n <= days; n++) {
  12.             let kgPerDay = Number(input[index]);
  13.             avrAmount += kgPerDay;
  14.             index++;
  15.             if (n === days) {
  16.                 if (((avrAmount / days).toFixed(2)) >= expectedAmount) {
  17.                     console.log(`Good job! Average gold per day: ${(avrAmount / days).toFixed(2)}.`);
  18.                 } else if (((avrAmount / days).toFixed(2)) < expectedAmount) {
  19.                     console.log(`You need ${(expectedAmount - ((avrAmount / days).toFixed(2))).toFixed(2)} gold.`)
  20.  
  21.                 }
  22.             }
  23.         }  
  24.     }
  25.  
  26. }
  27. exam(["2",
  28. "10",
  29. "3",
  30. "10",
  31. "10",
  32. "11",
  33. "20",
  34. "2",
  35. "20",
  36. "10"])
Advertisement
Add Comment
Please, Sign In to add comment