Liliana797979

counter strike - mid exam - fundamentals

Jun 29th, 2021
228
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.     //console.log(initialEnergy);
  4.     let energy = 0;
  5.     let wonBattle = 0;
  6.  
  7.    
  8.     for (const command of input) {
  9.         if (command !== "End of battle") {
  10.             energy = Number(command);
  11.             //console.log(energy);
  12.         } else {
  13.             console.log(`Won battles: ${wonBattle}. Energy left: ${energy}`);
  14.         }
  15.     }
  16.     if (wonBattle % 3 === 0) {
  17.         wonBattle++;
  18.     }
  19.     if (energy <= initialEnergy) {
  20.         console.log(`Not enough energy! Game ends with ${wonBattle} won battles and ${energy} energy`);
  21.         break;
  22.     }
  23.    
  24. }
  25.  
  26. counterStrike([
  27.     '100', '10', '10',
  28.     '10',  '1',  '2',
  29.     '3',   '73', '10'
  30.   ]);
  31.  
Advertisement
Add Comment
Please, Sign In to add comment