Liliana797979

counter strike - mid exam - fundamentals

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