Advertisement
astanchev

Passion Days

Aug 31st, 2019
1,112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.61 KB | None | 0 0
  1. function passionDays(input) {
  2. let money = Number(input.shift());
  3. let command = input.shift();
  4.  
  5. let purchases = 0;
  6. let price = 0.0;
  7.  
  8. while (command !== "mall.Enter") {
  9. command = input.shift();
  10. }
  11.  
  12. command = input.shift();
  13.  
  14. while (command !== "mall.Exit") {
  15. for(let i = 0; i < command.length; i++) {
  16.  
  17. let action = command.charCodeAt(i);
  18.  
  19. if (action >= 'A'.charCodeAt(0) && action <= 'Z'.charCodeAt(0)) {
  20. price = 0.5 * action;
  21. }
  22. else if (action >= 'a'.charCodeAt(0) && action <= 'z'.charCodeAt(0)) {
  23. price = 0.3 * action;
  24. }
  25. else if (action === '%'.charCodeAt(0)) {
  26. price = money * 0.5;
  27. }
  28. else if (action === '*'.charCodeAt(0)) {
  29. money += 10.0;
  30. continue;
  31. }
  32. else {
  33. price = action;
  34. }
  35.  
  36. if (price > money || money === 0) {
  37. continue;
  38. }
  39.  
  40. money -= price;
  41. purchases++;
  42. }
  43.  
  44. command = input.shift();
  45. }
  46.  
  47. if (purchases === 0) {
  48. console.log(`No purchases. Money left: ${money.toFixed(2)} lv.`);
  49. } else {
  50. console.log(`${purchases} purchases. Money left: ${money.toFixed(2)} lv.`);
  51. }
  52. }
  53.  
  54. passionDays(["110", "mall.Enter", "d", "mall.Exit"]);
  55. console.log();
  56. passionDays(["110", "mall.Enter", "%", "mall.Exit"]);
  57. console.log();
  58. passionDays(["100", "mall.Enter", "Ab", "**", "mall.Exit"]);
  59. console.log();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement