TZinovieva

Suitcases Load

Jan 6th, 2023
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function suitcaseLoad1(input) {
  2.     let planeCapacity = Number(input[0]);
  3.  
  4.     let index = 1;
  5.     let command = input[1];
  6.     index++;
  7.  
  8.     let suitcasesLoaded = 0;
  9.     while (command !== "End") {
  10.         let suitcase = Number(command);
  11.         suitcasesLoaded++;
  12.  
  13.     if (suitcasesLoaded % 3 === 0) {
  14.         suitcase += suitcase * 0.10;
  15.     }
  16.     planeCapacity -= suitcase;
  17.  
  18.     if (planeCapacity < 0) {
  19.         suitcasesLoaded--;
  20.         break;
  21.     }
  22.     command = input[index];
  23.     index++;
  24.     }
  25. if (planeCapacity > 0) {
  26.     console.log("Congratulations! All suitcases are loaded!");
  27. } else {
  28.     console.log("No more space!");
  29. }
  30. console.log(`Statistic: ${suitcasesLoaded} suitcases loaded.`);
  31. }
Advertisement
Add Comment
Please, Sign In to add comment