Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function walking(input) {
- let command = input.shift() ;
- let target = 10000;
- let totalStepsWalked = 0 ;
- /////////////////////// WORKING /////////////////////////
- while ( command !=`Going home`) {
- let inputSteps = Number(command);
- totalStepsWalked += inputSteps ;
- if ( totalStepsWalked >= target ) {
- console.log("Goal reached! Good job!");
- break ;
- }
- command = input.shift() ;
- } // End of while
- if ( command ==`Going home` ) {
- let lastSteps = Number(input.shift(command));
- totalStepsWalked += lastSteps ;
- if ( totalStepsWalked >= target) {
- console.log("Goal reached! Good job!");
- }
- else {
- console.log(`${target - totalStepsWalked} more steps to reach goal.`);
- }
- }
- }
- walking ([`1500`,`300`,`2500`,`3000`,`Going home`,`200`]);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement