Advertisement
VoidRay

#moving #while-loop #programing-basics

Nov 29th, 2019
675
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.62 KB | None | 0 0
  1. function moving(input){
  2. var width = Number(input.shift());
  3. var length = Number(input.shift());
  4. var height = Number(input.shift());
  5. var volume = width*length*height;
  6. var movedCartons = 0;
  7.  
  8. while(true){
  9. numCartons = input.shift();
  10. if(isNaN(numCartons) || numCartons=="undefined" || numCartons=="Done"){
  11. break;
  12. }
  13. else{
  14. movedCartons+=numCartons;
  15. }
  16. }
  17.  
  18. if(movedCartons>volume){
  19. console.log(`No more free space! You need ${Math.abs(movedCartons - volume)} Cubic meters more.`);
  20. }
  21. else console.log(`${Math.abs(movedCartons - volume)} Cubic meters left.`);
  22. }
  23.  
  24. moving([10,1,2,4,6,"Done"]);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement