Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function solve(input) {
- let targetSteps = 10000;
- let herSteps = 0;
- let index = 0;
- let difference = 0;
- while (!isNaN(input[index])) {
- herSteps += Number(input[index]);
- if (herSteps >= targetSteps) {
- difference = herSteps - targetSteps;
- console.log('Goal reached! Good job!');
- console.log(`${difference} steps over the goal!`);
- }
- index++;
- } // While loop
- if (isNaN(input[index]) && input[index] !== undefined) {
- index = index + 1;
- herSteps += Number(input[index]);
- difference = herSteps - targetSteps;
- difference = Math.abs(difference);
- if (herSteps >= targetSteps) {
- difference = herSteps - targetSteps;
- console.log('Goal reached! Good job!');
- console.log(`${difference} steps over the goal!`);
- } else {
- console.log(`${difference} more steps to reach goal.`);
- }
- }
- } // function
Advertisement
Add Comment
Please, Sign In to add comment