Advertisement
Liliana797979

viarno reshenie cake1

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