Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function renovation(input) {
- let index = 0;
- let wallHeight = Number(input[index]);
- index++;
- let wallWidth = Number(input[index]);
- index++;
- let skippedSurface = Number(input[index]);
- index++;
- let command = input[index];
- index++;
- let totalSurface = wallHeight * wallWidth * 4;
- let paintedSurface = Math.ceil(totalSurface - (totalSurface * (skippedSurface / 100)));
- let wallsPainted = false;
- while (command !== "Tired!") {
- let paintLitres = Number(command);
- if (paintedSurface - paintLitres < 0) {
- wallsPainted = true;
- console.log(`All walls are painted and you have ${paintLitres - paintedSurface} l paint left!`);
- break;
- } else if (paintedSurface - paintLitres === 0) {
- wallsPainted = true;
- console.log(`All walls are painted! Great job, Pesho!`);
- break;
- } else {
- paintedSurface -= paintLitres;
- }
- command = input[index];
- index++;
- }
- if (!wallsPainted) {
- console.log(`${paintedSurface} quadratic m left.`);
- }
- }
- renovation(["3", "5", "10", "2", "3", "4", "Tired!"]);
- renovation(["2", "3", "25", "6", "7", "8"]);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement