ErolKZ

Untitled

Jul 4th, 2021
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.08 KB | None | 0 0
  1. function solve(input) {
  2.  
  3. let targetSteps = 10000;
  4.  
  5. let herSteps = 0;
  6.  
  7. let index = 0;
  8.  
  9. let difference = 0;
  10.  
  11.  
  12.  
  13.  
  14. while (!isNaN(input[index])) {
  15.  
  16.  
  17.  
  18. herSteps += Number(input[index]);
  19.  
  20. if (herSteps >= targetSteps) {
  21.  
  22. difference = herSteps - targetSteps;
  23.  
  24. console.log('Goal reached! Good job!');
  25. console.log(`${difference} steps over the goal!`);
  26.  
  27. }
  28.  
  29.  
  30. index++;
  31.  
  32. } // While loop
  33.  
  34.  
  35. if (isNaN(input[index]) && input[index] !== undefined) {
  36.  
  37. index = index + 1;
  38.  
  39. herSteps += Number(input[index]);
  40.  
  41. difference = herSteps - targetSteps;
  42.  
  43. difference = Math.abs(difference);
  44.  
  45.  
  46. if (herSteps >= targetSteps) {
  47.  
  48. difference = herSteps - targetSteps;
  49.  
  50. console.log('Goal reached! Good job!');
  51. console.log(`${difference} steps over the goal!`);
  52.  
  53.  
  54. } else {
  55.  
  56. console.log(`${difference} more steps to reach goal.`);
  57.  
  58. }
  59.  
  60.  
  61.  
  62.  
  63. }
  64.  
  65.  
  66. } // function
Advertisement
Add Comment
Please, Sign In to add comment