Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function cake(input) {
- let l = Number(input.shift());
- let w = Number(input.shift());
- let cake = l * w;
- let command = input.shift();
- let cakeSlise = 0;
- let counter = 0;
- while (cakeSlise <= cake) {
- if (command === 'STOP') {
- break;
- }
- let takeSlise = Number(command);
- cakeSlise += takeSlise;
- counter++;
- command = input.shift();
- }
- if (cakeSlise < cake) {
- let leftSlice = Math.abs(cake - cakeSlise);
- console.log(`${leftSlice} pieces are left.`);
- }
- else if (cakeSlise >= cake) {
- let left = Math.abs(cakeSlise - cake);
- console.log(`No more cake left! You need ${left} pieces more.`);
- }
- }
Add Comment
Please, Sign In to add comment