MartenBG

Untitled

Feb 16th, 2019
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.62 KB | None | 0 0
  1. function lily(input) {
  2. let age = +(input.shift());
  3. let washingMashinePrice = +(input.shift());
  4. let toysPrice = +(input.shift());
  5. let saves = 0;
  6. let money = 0;
  7. let countToys = 0;
  8. for (let i = 1; i <= age; i++) {
  9. if (i % 2 == 0) {
  10. money += (10 * i / 2) - 1;
  11. } else {
  12. countToys++;
  13. }
  14. }
  15. saves = money + countToys * toysPrice;
  16. if (saves >= washingMashinePrice) {
  17. console.log(`Yes! ${(saves - washingMashinePrice).toFixed(2)}`);
  18. } else {
  19. console.log(`No! ${(washingMashinePrice - saves).toFixed(2)}`);
  20. }
  21. }
Advertisement
Add Comment
Please, Sign In to add comment