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