Advertisement
Guest User

Untitled

a guest
Dec 4th, 2020
287
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function luggage(input) {
  2.     let capacity = Number(input.shift());
  3.     let baggageCounter = 0;
  4.    
  5.  
  6.  
  7.     let command = input.shift();
  8.     while (command !== 'End') {
  9.         let baggage = Number(command);
  10.         capacity -= baggage;
  11.    
  12.         if (capacity < 0) {
  13.             break;
  14.         }
  15.        
  16.        
  17.        
  18.         if (baggageCounter % 3 === 0) {
  19.             baggage = baggage * 1.10;
  20.         }
  21.         baggageCounter++;
  22.  
  23.         command = input.shift();
  24.  
  25.     }
  26.     if (capacity > 0) {
  27.         console.log("Congratulations! All suitcases are loaded!");
  28.         console.log(`Statistic: ${baggageCounter} suitcases loaded.`);
  29.     } else {
  30.         console.log("No more space!");
  31.         console.log(`Statistic: ${baggageCounter} suitcases loaded.`);
  32.  
  33.     }
  34.  
  35.  
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement