Advertisement
Liliana797979

viarno reshenie cake2

Feb 12th, 2021
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function cake(input) {
  2.     let lenght = Number(input[0]);
  3.     let weigth = Number(input[1]);
  4.     let index = 2;
  5.     let pieceCake = input[index];
  6.     let area = lenght * weigth;
  7.     index++;
  8.  
  9.     while (pieceCake !== "STOP") {
  10.         let numberOfPieces = Number(pieceCake);
  11.         area -= numberOfPieces;
  12.         if (area < 0) {
  13.             console.log(`No more cake left! You need ${Math.abs(area)} pieces more.`)
  14.             break;
  15.         }
  16.         pieceCake = input[index];
  17.         index++;
  18.     }
  19.     if (area > 0) {
  20.         console.log(`${area} pieces are left.`)
  21.     }
  22.  
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement