Advertisement
Grossos

Traveling

Jun 20th, 2023 (edited)
893
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function traveling(input) {
  2.     let index = 0;
  3.     let command = input[index];
  4.  
  5.     while (command !== 'End') {
  6.         let destination = command;
  7.         index++;
  8.         let budget = Number(input[index]);
  9.         index++;
  10.  
  11.         let save = 0;
  12.         while (save < budget) {
  13.  
  14.             let money = Number(input[index]);
  15.             index++;
  16.             save += money;
  17.         }
  18.  
  19.         console.log(`Going to ${destination}!`);
  20.  
  21.         command = input[index];
  22.         index++;
  23.  
  24.         money = Number(input[index]);
  25.         index--;
  26.  
  27.     }
  28.  
  29. }
  30. traveling(["France",
  31.     "2000",
  32.     "300",
  33.     "300",
  34.     "200",
  35.     "400",
  36.     "190",
  37.     "258",
  38.     "360",
  39.     "Portugal",  // 9
  40.     "1450",     // 10
  41.     "400",      // 11
  42.     "400",      // 12
  43.     "200",      // 13
  44.     "300",       // 14
  45.     "300",      // 15
  46.     "Egypt",     // 16
  47.     "1900",      // 17
  48.     "1000",      //18
  49.     "280",      //19
  50.     "300",
  51.     "500",
  52.     "End"])
  53.  
  54.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement