Advertisement
Guest User

Untitled

a guest
Mar 31st, 2020
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.77 KB | None | 0 0
  1. function passionDays(input) {
  2. let budget = Number(input.shift());
  3. let command = input.shift();
  4. let counter = 0;
  5. let isNoShopping = false;
  6.  
  7. if (command === "mall.Enter") {
  8. command = input.shift();
  9. while (command !== "mall.Exit") {
  10. for (let i = 0; i < command.length; i++) {
  11. if (command.charCodeAt(i) >= 65 && command.charCodeAt(i) <= 90) {
  12. if (command.charCodeAt(i) / 2 > budget) {
  13. isNoShopping = true;
  14. break;
  15. }
  16. budget = budget - command.charCodeAt(i) / 2;
  17. } else if (
  18. command.charCodeAt(i) >= 97 &&
  19. command.charCodeAt(i) <= 122
  20. ) {
  21. if (command.charCodeAt(i) * 0.3 > budget) {
  22. isNoShopping = true;
  23. break;
  24. }
  25. budget -= command.charCodeAt(i) * 0.3;
  26. } else if (command[i] === "%") {
  27. if (command.charCodeAt(i) > budget) {
  28. isNoShopping = true;
  29. break;
  30. }
  31. budget = budget / 2;
  32. } else if (command[i] === "*") {
  33. budget += 10;
  34. } else {
  35. if (command.charCodeAt(i) > budget) {
  36. isNoShopping = true;
  37. break;
  38. }
  39. budget -= command.charCodeAt(i);
  40. }
  41. }
  42. if (isNoShopping === true) {
  43. break;
  44. }
  45. counter++;
  46. command = input.shift();
  47. }
  48. }
  49. if (counter === 0) {
  50. console.log(`No purchases. Money left: ${budget.toFixed(2)} lv.`);
  51. } else if (counter > 0) {
  52. console.log(`${counter} purchases. Money left: ${budget.toFixed(2)} lv.`);
  53. }
  54. }
  55. passionDays([110, "mall.Enter", "%", "a", "b", "a", "mall.Exit"]);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement