Advertisement
Guest User

Untitled

a guest
May 23rd, 2019
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.98 KB | None | 0 0
  1. function solve(input) {
  2. let days = +input[0];
  3. let tips = +input[1];
  4. let lunchPrice = +input[2];
  5. let salary = +input[3];
  6. let carPrice = +input[4];
  7.  
  8. let savings = 0;
  9. for (let i = 1; i <= days; i++) {
  10. let day = i % 7;
  11. if (day === 5 || day === 6) {
  12. savings += tips;
  13. } else if (day === 0) {
  14. savings -= tips * 2;
  15. } else {
  16. savings += tips - lunchPrice;
  17. }
  18.  
  19. if (i % 15 === 0) {
  20. savings += salary;
  21. }
  22. if (i % 30 === 0) {
  23. savings -= 4 * (tips - lunchPrice);
  24. }
  25. }
  26.  
  27. if (days % 15 === 0) {
  28.  
  29. console.log(`George finished the season with ${savings.toFixed(2)} levs.`);
  30. } else {
  31. console.log(`George left the job with ${savings.toFixed(2)} levs.`);
  32. }
  33. if (savings >= carPrice) {
  34. console.log('He bought a car.');
  35. }
  36. else{
  37. console.log('He called for a ride home.');
  38. }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement