Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function solution(input) {
- let command = input.shift();
- let i = 0;
- let stepCounter = 0;
- let target = 10000;
- let res = 0;
- while (command !== "Going home" || stepCounter < target) {
- let currentSteps = Number(command);
- command = input.shift();
- i++;
- stepCounter += currentSteps;
- res = target - stepCounter;
- if(stepCounter>=target){
- console.log("Goal reached! Good job!");
- }
- if (command == "Going home") {
- command = input.shift()
- res -= command;
- console.log(`${res} more steps to reach goal.`)
- break
- }
- }
- }
- solution([
- "125",
- "250",
- "4000",
- "30",
- "2678",
- "4682",
- ])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement