Advertisement
ErolKZ

Untitled

Jun 26th, 2021
20
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.96 KB | None | 0 0
  1.  
  2. function solve(input) {
  3.  
  4.  
  5.  
  6. let ageLily = Number(input[0]);
  7.  
  8. let priceWashingMachine = Number(input[1]);
  9.  
  10. let priceOneToy = Number(input[2]);
  11.  
  12.  
  13. let odd = 0;
  14.  
  15. let even = 0;
  16.  
  17. let toysPrice = 0;
  18.  
  19. let moneyFinal = 0;
  20.  
  21. let moneyPerBirth = 0;
  22.  
  23. let allMoney = 0;
  24.  
  25. let moneyLeft = 0;
  26.  
  27. let countIncrease = 10;
  28.  
  29.  
  30. for (let i = 1; i <= ageLily; i++) {
  31.  
  32. if (i % 2 !== 0) {
  33.  
  34. odd += 1;
  35.  
  36. } else {
  37.  
  38. even += 1;
  39.  
  40. }
  41.  
  42. }
  43.  
  44.  
  45.  
  46.  
  47. for (let i = 1; i <= even; i++) {
  48.  
  49.  
  50. moneyPerBirth += countIncrease;
  51.  
  52. countIncrease += 10;
  53.  
  54.  
  55. }
  56.  
  57.  
  58. moneyFinal = moneyPerBirth - even;
  59.  
  60. toysPrice = odd * priceOneToy;
  61.  
  62. allMoney = moneyFinal + toysPrice;
  63.  
  64. moneyLeft = allMoney - priceWashingMachine;
  65.  
  66.  
  67. if (allMoney >= priceWashingMachine) {
  68.  
  69. console.log(`Yes! ${moneyLeft.toFixed(2)}`);
  70.  
  71. } else {
  72.  
  73. moneyLeft = Math.abs(moneyLeft);
  74.  
  75. console.log(`No! ${moneyLeft.toFixed(2)}`);
  76.  
  77. }
  78.  
  79.  
  80. }
  81.  
  82.  
  83.  
  84. solve([
  85.  
  86. '10',
  87. '170',
  88. '6'
  89.  
  90. ]);
  91.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement