SHARE
TWEET

Untitled

a guest Jun 24th, 2019 70 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function walking(input) {
  2.  
  3.     let command = input.shift() ;
  4.     let target = 10000;
  5.     let totalStepsWalked = 0 ;
  6.  
  7.  /////////////////////// WORKING /////////////////////////
  8.  
  9.     while ( command !=`Going home`) {
  10.  
  11.         let inputSteps = Number(command);
  12.         totalStepsWalked += inputSteps ;
  13.  
  14.         if ( totalStepsWalked >= target ) {
  15.  
  16.             console.log("Goal reached! Good job!");
  17.             break ;
  18.         }
  19.  
  20.         command = input.shift() ;
  21.      
  22.     } // End of while
  23.  
  24.     if ( command ==`Going home` ) {
  25.  
  26.         let lastSteps = Number(input.shift(command));
  27.         totalStepsWalked += lastSteps ;
  28.  
  29.         if ( totalStepsWalked >= target) {
  30.  
  31.             console.log("Goal reached! Good job!");
  32.            
  33.  
  34.         }
  35.  
  36.         else {
  37.  
  38.             console.log(`${target - totalStepsWalked} more steps to reach goal.`);
  39.         }
  40.  
  41.     }
  42.  
  43. }
  44.    
  45. walking ([`1500`,`300`,`2500`,`3000`,`Going home`,`200`]);
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top