Advertisement
Guest User

Untitled

a guest
Jun 24th, 2019
335
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.94 KB | None | 0 0
  1. function walking(input) {
  2.  
  3. let command = input.shift() ;
  4. let target = 10000;
  5. let totalStepsWalked = 0 ;
  6.  
  7. ///////////////////////NOT WORKING /////////////////////////
  8.  
  9. while ( command !=`Going home`) {
  10.  
  11. let inputSteps = Number(input.shift(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());
  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 ([`1000`,`1500`,`2000`,`6000`]);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement