vikkktor

Walking

Jun 11th, 2021 (edited)
881
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function walking(input) {
  2.     let inputL = input.length;
  3.     let target = 10000;
  4.  
  5.     let totalSteps = 0;
  6.     let steps = 0;
  7.  
  8.     let index = 0;
  9.     let command = input[index];
  10.     index++;
  11.  
  12.     while (index <= inputL) {
  13.         if (command === "Going home") {
  14.             command = input[index];
  15.             index++
  16.             continue;
  17.         }
  18.         steps = Number(command);
  19.         totalSteps += Number(steps);
  20.  
  21.         command = input[index];
  22.         index++;
  23.     }
  24.  
  25.     if (totalSteps > target) {
  26.         console.log(`Goal reached! Good job!`);
  27.         console.log(`${totalSteps - target} steps over the goal!`);
  28.     } else {
  29.         console.log(`${(target - totalSteps)} more steps to reach goal.`)
  30.     }
  31. }
RAW Paste Data