Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function solve(input) {
- let targetSteps = 10000;
- let stepsSheMade = 0;
- let difference = 0;
- let index = 0;
- while (input[index] !== undefined) {
- if (!isNaN(input[index])) {
- stepsSheMade += Number(input[index]);
- }
- if (stepsSheMade >= targetSteps && input[index] !== `Going home`) {
- difference = stepsSheMade - targetSteps;
- console.log('Goal reached! Good job!');
- console.log(`${difference} steps over the goal!`);
- }
- if (input[index] === `Going home`) {
- index = index + 1;
- stepsSheMade += Number(input[index]);
- difference = stepsSheMade - targetSteps;
- difference = Math.abs(difference);
- console.log(`${difference} more steps to reach goal.`);
- break;
- }
- index++;
- }
- }
- solve([
- '1500',
- '3000',
- '250',
- '1548',
- '2000',
- 'Going home',
- '2000'
- // '1500',
- // '300',
- // '2500',
- // '3000',
- // 'Going home',
- // '200'
- // '1000',
- // '1500',
- // '2000',
- // '6500'
- ]);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement