Advertisement
dimoBs

02. MuOnline1

Feb 21st, 2021
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.40 KB | None | 0 0
  1. function solve(input) {
  2.  
  3. let intialHealt = 100;
  4. let bitcoins = 0;
  5. let array = input.split('|')
  6. let count = 0;
  7. let flag = true;
  8. health = intialHealt;
  9.  
  10. array.forEach(element => {
  11. if (health > 0) {
  12. count++;
  13. let [dungeons, score] = element.split(' ');
  14. score = Number(score);
  15. if (dungeons === 'potion' && health + score >= intialHealt) {
  16. console.log(`You healed for ${(intialHealt - health)} hp.`);
  17. health = intialHealt;
  18. console.log(`Current health: ${health} hp.`);
  19. } else if (dungeons === 'potion' && health + score < intialHealt) {
  20. health += score;
  21. console.log(`You healed for ${score} hp.`);
  22. console.log(`Current health: ${health} hp.`);
  23. } else if (dungeons === 'chest') {
  24. bitcoins += score;
  25. console.log(`You found ${score} bitcoins.`);
  26. } else {
  27. health -= score;
  28. if (health > 0) {
  29. console.log(`You slayed ${dungeons}.`);
  30. }
  31. if (health <= 0) {
  32. console.log(`You died! Killed by ${dungeons}.`);
  33. console.log(`Best room: ${count}`);
  34. flag = false;
  35. }
  36. }
  37. }
  38. });
  39. if (flag) {
  40. console.log(`You've made it!\nBitcoins: ${bitcoins}\nHealth: ${health}`)
  41. }
  42. }
  43. solve('cat 10|potion 30|orc 10|chest 10|snake 25|chest 110')
  44. //solve('rat 10|bat 20|potion 10|rat 10|chest 100|boss 70|chest 1000')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement