TZinovieva

Traveling JS 100/100

Oct 25th, 2022
71
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 destination = input[index];
  4.     index++;
  5.  
  6.     while (destination !== "End") {
  7.         let budget = Number(input[index]);
  8.         index++;
  9.         let totalSavedMoney = 0;
  10.  
  11.         while (totalSavedMoney < budget) {
  12.         let savedMoney = Number(input[index]);
  13.         index++;
  14.         totalSavedMoney += savedMoney;
  15.  
  16.         if (totalSavedMoney >= budget) {
  17.             console.log(`Going to ${destination}!`);
  18.         }
  19.     }
  20.         destination = input[index];
  21.         index++;
  22.         }
  23.     }
Advertisement
Add Comment
Please, Sign In to add comment