Advertisement
teofarov13

Untitled

Feb 19th, 2023
521
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function experienceGaining(input) {
  2.  
  3.     let neededExperience = input.shift();
  4.     let countOfBattles = input.shift();
  5.  
  6.  
  7.     let collectedExperience = 0;
  8.     let battleCount = 0
  9.  
  10.     for (let i = 0; i < input.length; i++) {
  11.         battleCount++
  12.         let currExp = input[i];
  13.  
  14.  
  15.         if (battleCount % 3 !== 0 && battleCount % 5 !== 0 && battleCount % 15 !== 0) {
  16.             collectedExperience += currExp
  17.         }
  18.  
  19.         if (battleCount % 3 === 0) {
  20.  
  21.             collectedExperience += currExp + (currExp * 0.15);
  22.         }
  23.  
  24.         if (battleCount % 5 === 0) {
  25.  
  26.             collectedExperience += currExp - (currExp * 0.1);
  27.         }
  28.  
  29.         if (battleCount % 15 === 0) {
  30.  
  31.             collectedExperience += currExp + (currExp * 0.5);
  32.         }
  33.         if (collectedExperience >= neededExperience) {
  34.             break;
  35.         }
  36.  
  37.     }
  38.     if (collectedExperience >= neededExperience) {
  39.         console.log(`Player successfully collected his needed experience for ${battleCount} battles.`);
  40.     } else {
  41.         console.log(`Player was not able to collect the needed experience, ${(neededExperience - collectedExperience).toFixed(2)} more needed.`);
  42.          
  43.     }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement