Advertisement
vladovip

JS_FUND_ experienceGaining_MIDEX

Feb 19th, 2023 (edited)
549
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solve(inputArr) {
  2. //  Coding Tasks Done!!! :) 3 out of 3 answers :)
  3.  
  4. let neededExperience = Number(inputArr.shift());
  5. let numOfBattles = Number(inputArr.shift());
  6. let initalExperience = 0;
  7. let counterBattles = 0;
  8. //solve([50, 100, 200, 100, 30]);
  9. for (let index = 0; index < inputArr.length; index++) {
  10.      
  11.     if ( initalExperience <  neededExperience  && counterBattles <= numOfBattles ) {
  12.         let currentExperience = Number(inputArr[index]);
  13.         counterBattles +=1;
  14.         if( counterBattles % 3 === 0){
  15.             initalExperience += currentExperience + 0.15*currentExperience;
  16.         } else if (counterBattles % 5 === 0){
  17.             initalExperience +=  currentExperience* 0.90;
  18.         } else if ( counterBattles % 3 === 0 && counterBattles % 5 === 0 ){
  19.             initalExperience += (currentExperience + 0.05*currentExperience);
  20.         } else {
  21.             initalExperience += currentExperience;
  22.         }
  23.     }  
  24.  
  25.      if (initalExperience >= neededExperience){
  26.         console.log(`Player successfully collected his needed experience for ${counterBattles} battles.`);
  27.         return;
  28.      }    
  29. }
  30.  
  31.  if ( initalExperience <  neededExperience) {
  32.     let difference =   neededExperience - initalExperience;
  33.     console.log(`Player was not able to collect the needed experience, ${difference.toFixed(2)} more needed.`);
  34.     return;
  35. }
  36.  
  37.  
  38. }
  39.  
  40.  
  41. solve([500, 5, 50, 100, 200, 100, 30]);
  42. console.log(`***********`);
  43. solve([500, 5, 50, 100, 200, 100, 20]);
  44. console.log(`***********`);
  45. solve([400, 5, 50, 100, 200, 100, 20]);
  46.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement