Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function counterStrike(input) {
- let initialEnergy = Number(input.shift());
- let wonBattlesCounter = 0;
- let index = 0;
- while (input[index] !== "End of battle") {
- let distance = Number(input[index]);
- if (initialEnergy < distance) {
- console.log(`Not enough energy! Game ends with ${wonBattlesCounter} won battles and ${initialEnergy} energy`);
- return;
- }
- wonBattlesCounter++;
- initialEnergy -= distance;
- if (wonBattlesCounter % 3 == 0) {
- initialEnergy += wonBattlesCounter;
- }
- index++;
- }
- console.log(`Won battles: ${wonBattlesCounter}. Energy left: ${initialEnergy}`);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement