Advertisement
Guest User

Untitled

a guest
Mar 20th, 2019
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.69 KB | None | 0 0
  1. function walking(input) {
  2. let steps = input.shift();
  3. let remaining = 10000;
  4. let isGoalReached = false;
  5.  
  6. while (steps != "Going home") {
  7. steps = Number(steps);
  8. remaining -= steps;
  9. steps = input.shift();
  10. if (remaining <= 0) {
  11. isGoalReached = true;
  12. break;
  13. }
  14. }
  15. if (steps == "Going home") {
  16. steps = Number(input.shift());
  17. remaining -= steps;
  18. if (remaining <= 0) {
  19. isGoalReached = true;
  20. }
  21. }
  22. if (isGoalReached) {
  23. console.log("Goal reached! Good job!");
  24. } else {
  25. console.log(`${remaining} more steps to reach goal.`);
  26. }
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement