Advertisement
AlexandrP

04. Walking

Dec 7th, 2022
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function walk (input){
  2.  
  3. index = 0
  4. let totalSteps = Number (input [index])
  5. index++
  6.  
  7. let steps = 0
  8. let difference = 0
  9.  
  10. while (steps != "Going home"){
  11.     stepsAsNumber = Number (steps)
  12.     totalSteps = totalSteps + stepsAsNumber
  13.         if (totalSteps >= 10000){
  14.         difference = totalSteps - 10000
  15.         console.log ("Goal reached! Good job!")
  16.         console.log(`${difference} steps over the goal!`);
  17.         return}
  18.  
  19.       steps = (input [index])
  20.       index++
  21. }
  22.  
  23. steps = input [index]
  24. stepsAsNumber = Number (steps)
  25. totalSteps = totalSteps + stepsAsNumber
  26.  
  27. if (totalSteps >= 10000){
  28.     difference = totalSteps - 10000
  29.     console.log ("Goal reached! Good job!")
  30.     console.log(`${difference} steps over the goal!`);
  31.    
  32. }else{
  33. difference = 10000 - totalSteps
  34. console.log(`${difference} more steps to reach goal.`);
  35. }
  36.  
  37. }
  38. walk (["1500",
  39. "300",
  40. "2500",
  41. "3000",
  42. "Going home",
  43. "200"])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement