Advertisement
AlexandrP

05. Traveling

Dec 8th, 2022 (edited)
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function travel(input) {
  2.  
  3.   let index = 0
  4.   let destination = input[index];
  5.   index++
  6.   let neededSum = Number (input[index]);
  7.   index++;
  8.   let moneyOrDestination = 0
  9.  
  10.  
  11.   let sum = 0;
  12.  
  13.   while (moneyOrDestination !== "End") {
  14.     moneyOrDestination = Number (moneyOrDestination);
  15.  
  16.     if (sum >= neededSum) {
  17.       console.log(`Going to ${destination}!`);
  18.  
  19.       destination = input[index-1];
  20.    
  21.       neededSum = Number (input [index])
  22.       index++
  23.       sum = 0
  24.       moneyOrDestination = 0
  25.    
  26.     }
  27.  
  28.    
  29.  
  30.     sum = sum + moneyOrDestination;
  31.    
  32.     moneyOrDestination = input [index];
  33.  
  34.     index++;
  35.  
  36.    
  37.   }
  38.  
  39.  
  40.   if (sum >= neededSum) {
  41.     console.log(`Going to ${destination}!`);
  42.   }
  43.  
  44. }
  45.  
  46.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement