Advertisement
Guest User

Cake

a guest
Jun 16th, 2019
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solve(input) {
  2.     let widht = Number(input.shift());
  3.     let lenght = Number(input.shift());
  4.     let cakeSize = widht * lenght;
  5.     let counter = 0;
  6.     let command = input.shift();
  7.     while(command !== "STOP") {
  8.         let cakesCount = Number(command);
  9.         counter += cakesCount;
  10.         if (cakeSize <= counter) {
  11.             break;
  12.         }
  13.         command = input.shift();
  14.     }
  15.     if(command === "STOP"){
  16.         console.log(`${cakeSize - counter} pieces are left.`);
  17.     }else {
  18.         console.log(`No more cake left! You need ${Math.abs(cakeSize - counter)} pieces more.`);
  19.     }
  20. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement