Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function walking(input) {
- let steps = input.shift();
- let remaining = 10000;
- let isGoalReached = false;
- while (steps != "Going home") {
- steps = Number(steps);
- remaining -= steps;
- steps = input.shift();
- if (remaining <= 0) {
- isGoalReached = true;
- break;
- }
- }
- if (steps == "Going home") {
- steps = Number(input.shift());
- remaining -= steps;
- if (remaining <= 0) {
- isGoalReached = true;
- }
- }
- if (isGoalReached) {
- console.log("Goal reached! Good job!");
- } else {
- console.log(`${remaining} more steps to reach goal.`);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement