Advertisement
Spocoman

01. Counter-Strike

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