Advertisement
Guest User

Walking

a guest
Mar 16th, 2019
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function walking(input) {
  2.     let currentsteps = input.shift();
  3.     let sumsteps = 0;
  4.     let isgoal = false;
  5.  
  6.     while (sumsteps < 10000) {
  7.         if (currentsteps === "Going home") {  
  8.             currentsteps = Number(input.shift());  
  9.             sumsteps += currentsteps;
  10.  
  11.             if (sumsteps >= 10000) {
  12.                 isgoal = true;
  13.             }
  14.  
  15.             break;
  16.         }
  17.  
  18.         currentsteps = Number(currentsteps);
  19.         sumsteps += currentsteps;
  20.         currentsteps = input.shift();
  21.     }
  22.  
  23.     if (isgoal || sumsteps >= 10000) {
  24.         console.log('Goal reached! Good job!')
  25.  
  26.     } else {
  27.         let diff = 10000 - sumsteps;
  28.         console.log(`${diff} more steps to reach goal.`)
  29.     }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement