Didart

Moving

Apr 19th, 2022
777
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 freeSpace = width * length * height;
  7.  
  8.     let index = 3;
  9.     let command = input[index];
  10.  
  11.     while (command !== 'Done') {
  12.  
  13.         let numberOfBoxes = Number(command);
  14.         freeSpace -= numberOfBoxes;
  15.  
  16.         if (freeSpace < 0) {
  17.             console.log(`No more free space! You need ${Math.abs(freeSpace)} Cubic meters more.`);
  18.             break;
  19.         }
  20.         index++;
  21.         command = input[index];
  22.     }
  23.  
  24.     if (freeSpace >= 0) {
  25.         console.log(`${freeSpace} Cubic meters left.`);
  26.     }
  27. }
  28.  
  29. moving(["10", "10", "2", "20", "20", "20", "20", "122"])
  30.  
  31.  
Advertisement
Add Comment
Please, Sign In to add comment