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