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