Advertisement
divanov94

Untitled

Jun 26th, 2020
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function cs(input){
  2.     let arr=input.slice();
  3.     let initialEnergy=arr.shift();
  4.     let winCount=0;
  5.     for (const commands of arr) {
  6.         if(commands!=="End of battle"){
  7.             let energy=Number(commands);
  8.             if(initialEnergy-energy<0){
  9.                 console.log(`Not enough energy! Game ends with ${winCount} won battles and ${initialEnergy} energy`);
  10.                 return;
  11.             }
  12.  
  13.  
  14.  
  15.             initialEnergy-=energy;
  16.             winCount++
  17.         }else {
  18.             console.log(`Won battles: ${winCount}. Energy left: ${initialEnergy}`);
  19.            
  20.         }
  21.         if(winCount%3==0){
  22.             initialEnergy+=winCount;
  23.         }
  24.        
  25.     }
  26.  
  27.    
  28.    
  29.    
  30.    
  31.  
  32.  
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement