Advertisement
Guest User

CounterStrike

a guest
Sep 14th, 2020
1,066
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function counterCtrice(inputArray){
  2.     let input = inputArray.slice();
  3.     let intitalEnergy = Number(input[0]);
  4.     let indexOfInput = 1;
  5.     let curWonBattels = 0;    
  6.  
  7.     while(intitalEnergy >= 0){
  8.         let distance = input[indexOfInput++];
  9.  
  10.         if(distance == 'End of battle'){
  11.             break;
  12.         } else {
  13.             distance = Number(distance);
  14.         }
  15.  
  16.         if(intitalEnergy >= distance){
  17.             curWonBattels++;
  18.             intitalEnergy -= distance;
  19.         } else {            
  20.             console.log(`Not enough energy! Game ends with ${curWonBattels} won battles and ${intitalEnergy} energy`);          
  21.             return;
  22.         }
  23.  
  24.         if(curWonBattels % 3 == 0){
  25.             intitalEnergy += curWonBattels;
  26.         }
  27.     }    
  28.     console.log(`Won battles: ${curWonBattels}. Energy left: ${intitalEnergy}`);
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement