Advertisement
svephoto

Counter Strike [JavaScript]

Jun 29th, 2021
1,514
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function counterStrike(input) {
  2.     let initialEnergy = Number(input.shift());
  3.  
  4.     let wonBattlesCounter = 0;
  5.     let index = 0;
  6.    
  7.     while (input[index] !== "End of battle") {
  8.         let distance = Number(input[index]);
  9.        
  10.         if (initialEnergy < distance) {
  11.             console.log(`Not enough energy! Game ends with ${wonBattlesCounter} won battles and ${initialEnergy} energy`);
  12.             return;
  13.         }
  14.      
  15.         wonBattlesCounter++;
  16.         initialEnergy -= distance;
  17.      
  18.         if (wonBattlesCounter % 3 == 0) {
  19.             initialEnergy += wonBattlesCounter;
  20.         }
  21.  
  22.         index++;
  23.     }
  24.  
  25.     console.log(`Won battles: ${wonBattlesCounter}. Energy left: ${initialEnergy}`);
  26. }
  27.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement