vborislavova

10. Moving - while - loops

Mar 4th, 2020
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function moving(input) {
  2.     let w = Number(input.shift());
  3.     let l = Number(input.shift());
  4.     let h = Number(input.shift());
  5.  
  6.     let totalFreeSpace = w * l * h;
  7.  
  8.     let command = input.shift();
  9.  
  10.     while (command !== "Done") {
  11.         let box = Number(command);
  12.         totalFreeSpace -=box;
  13.         if(totalFreeSpace < 0) {
  14.             break;
  15.         }
  16.         command = input.shift();
  17.     }
  18.     if(totalFreeSpace < 0) {
  19.         console.log(`No more free space! You need ${Math.abs(totalFreeSpace)} Cubic meters more.`);
  20.     }else {
  21.     console.log(`${totalFreeSpace} Cubic meters left.`);
  22.     }
  23. }
Add Comment
Please, Sign In to add comment