Advertisement
Guest User

Untitled

a guest
May 13th, 2020
565
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.69 KB | None | 0 0
  1. function solve(input = []) {
  2. let wonBattle = 0;
  3.  
  4. let health = Number(input.shift());
  5. for (const commands of input) {
  6. if (commands !== 'End of battle') {
  7. let energy = Number(commands);
  8. health -= energy;
  9. wonBattle++;
  10.  
  11. if (health <= 0) {
  12. //wonBattle--;
  13. console.log(`Not enough energy! Game ends with ${wonBattle} won battles and ${health} energy`);
  14. return;
  15. }
  16. }
  17.  
  18. else {
  19. console.log(`Won battles: ${wonBattle}. Energy left: ${health}`);
  20. }
  21.  
  22. if (wonBattle % 3 === 0) {
  23. health += wonBattle;
  24. }
  25. }
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement