Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function counterStrike(input) {
- let initialEnergy = Number(input.shift());
- //console.log(initialEnergy);
- let energy = 0;
- let wonBattle = 0;
- for (const command of input) {
- if (command !== "End of battle") {
- energy = Number(command);
- //console.log(energy);
- } else {
- console.log(`Won battles: ${wonBattle}. Energy left: ${energy}`);
- }
- }
- if (wonBattle % 3 === 0) {
- wonBattle++;
- }
- if (energy <= initialEnergy) {
- console.log(`Not enough energy! Game ends with ${wonBattle} won battles and ${energy} energy`);
- break;
- }
- }
- counterStrike([
- '100', '10', '10',
- '10', '1', '2',
- '3', '73', '10'
- ]);
Advertisement
Add Comment
Please, Sign In to add comment