Advertisement
gskorchev

walking

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