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