Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function walking(input) {
- let inputL = input.length;
- let target = 10000;
- let totalSteps = 0;
- let steps = 0;
- let index = 0;
- let command = input[index];
- index++;
- while (index <= inputL) {
- if (command === "Going home") {
- command = input[index];
- index++
- continue;
- }
- steps = Number(command);
- totalSteps += Number(steps);
- command = input[index];
- index++;
- }
- if (totalSteps > target) {
- console.log(`Goal reached! Good job!`);
- console.log(`${totalSteps - target} steps over the goal!`);
- } else {
- console.log(`${(target - totalSteps)} more steps to reach goal.`)
- }
- }
Add Comment
Please, Sign In to add comment