Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function solve(inputArr) {
- // Coding Tasks Done!!! :) 3 out of 3 answers :)
- let neededExperience = Number(inputArr.shift());
- let numOfBattles = Number(inputArr.shift());
- let initalExperience = 0;
- let counterBattles = 0;
- //solve([50, 100, 200, 100, 30]);
- for (let index = 0; index < inputArr.length; index++) {
- if ( initalExperience < neededExperience && counterBattles <= numOfBattles ) {
- let currentExperience = Number(inputArr[index]);
- counterBattles +=1;
- if( counterBattles % 3 === 0){
- initalExperience += currentExperience + 0.15*currentExperience;
- } else if (counterBattles % 5 === 0){
- initalExperience += currentExperience* 0.90;
- } else if ( counterBattles % 3 === 0 && counterBattles % 5 === 0 ){
- initalExperience += (currentExperience + 0.05*currentExperience);
- } else {
- initalExperience += currentExperience;
- }
- }
- if (initalExperience >= neededExperience){
- console.log(`Player successfully collected his needed experience for ${counterBattles} battles.`);
- return;
- }
- }
- if ( initalExperience < neededExperience) {
- let difference = neededExperience - initalExperience;
- console.log(`Player was not able to collect the needed experience, ${difference.toFixed(2)} more needed.`);
- return;
- }
- }
- solve([500, 5, 50, 100, 200, 100, 30]);
- console.log(`***********`);
- solve([500, 5, 50, 100, 200, 100, 20]);
- console.log(`***********`);
- solve([400, 5, 50, 100, 200, 100, 20]);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement