Advertisement
Guest User

Untitled

a guest
Feb 6th, 2019
706
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function cake(input) {
  2.     let l = Number(input.shift());
  3.     let w = Number(input.shift());
  4.     let area = l * w;
  5.     let total = 0;
  6.     while (area >= total) {
  7.         let current = input.shift();
  8. // вместо input, проверявай дали current === 'STOP'
  9.         if (current == "STOP") {
  10.             break;
  11.         }
  12.         let piece = Number(current);
  13.         total += piece;
  14.     }
  15.     if (total > area) {
  16.         let need = total - area;
  17.         console.log(`No more cake left! You need ${need} pieces more.`);
  18.     } else {
  19.         let left = area - total;
  20.         console.log(`${left} pieces are left.`);
  21.     }
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement