TZinovieva

Moving

Oct 17th, 2022
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function moving(input) {
  2.     let width = Number(input[0]);
  3.     let length = Number(input[1]);
  4.     let height = Number(input[2]);
  5.  
  6.     let index = 3;
  7.     let command = input[index];
  8.     index++;
  9.  
  10.     let freeSpace = width * length * height;
  11.     let totalBoxes = 0;
  12.  
  13.     while (command !== "Done") {
  14.         let boxes = Number(command);
  15.         totalBoxes += boxes;
  16.  
  17.         if (totalBoxes >= freeSpace) {
  18.             break;
  19.         }
  20.         command = input[index];
  21.         index++;
  22.     }
  23.     let freeSpaceLeft = freeSpace - totalBoxes;
  24.     if (freeSpace > totalBoxes) {
  25.         console.log(`${freeSpaceLeft} Cubic meters left.`);
  26.     } else {
  27.         console.log(`No more free space! You need ${Math.abs(freeSpaceLeft)} Cubic meters more.`);
  28.     }
  29. }
Advertisement
Add Comment
Please, Sign In to add comment