Advertisement
-Enigmos-

renovation.js

Nov 21st, 2021
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function renovation(input) {
  2.     let index = 0;
  3.     let wallHeight = Number(input[index]);
  4.     index++;
  5.     let wallWidth = Number(input[index]);
  6.     index++;
  7.     let skippedSurface = Number(input[index]);
  8.     index++;
  9.     let command = input[index];
  10.     index++;
  11.     let totalSurface = wallHeight * wallWidth * 4;
  12.     let paintedSurface = Math.ceil(totalSurface - (totalSurface * (skippedSurface / 100)));
  13.     let wallsPainted = false;
  14.  
  15.     while (command !== "Tired!") {
  16.         let paintLitres = Number(command);
  17.  
  18.         if (paintedSurface - paintLitres < 0) {
  19.             wallsPainted = true;
  20.             console.log(`All walls are painted and you have ${paintLitres - paintedSurface} l paint left!`);
  21.             break;
  22.         } else if (paintedSurface - paintLitres === 0) {
  23.             wallsPainted = true;
  24.             console.log(`All walls are painted! Great job, Pesho!`);
  25.             break;
  26.         } else {
  27.             paintedSurface -= paintLitres;
  28.         }
  29.        
  30.         command = input[index];
  31.         index++;
  32.     }
  33.  
  34.     if (!wallsPainted) {
  35.         console.log(`${paintedSurface} quadratic m left.`);
  36.     }
  37. }
  38.  
  39. renovation(["3", "5", "10", "2", "3", "4", "Tired!"]);
  40. renovation(["2", "3", "25", "6", "7", "8"]);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement