TZinovieva

Pipes In Pool 100/100

May 20th, 2022 (edited)
36
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function pipesInPool(input) {
  2.     let poolVolume = Number(input[0]);
  3.     let firstPipe = Number(input[1]);
  4.     let secondPipe = Number(input[2]);
  5.     let hours = Number(input[3]);
  6.  
  7.     let firstPipeVolume = firstPipe * hours;
  8.     let secondPipeVolume = secondPipe * hours;
  9.     let totalFill = firstPipeVolume + secondPipeVolume;
  10.     let totalFillPercent = totalFill * 100 / poolVolume;
  11.     let firstPipePercent = firstPipeVolume * 100 / totalFill;
  12.     let secondPipePercent = secondPipeVolume * 100 / totalFill;
  13.  
  14.     if (totalFill <= poolVolume) {
  15.     console.log(`The pool is ${totalFillPercent.toFixed(2)}% full. Pipe 1: ${firstPipePercent.toFixed(2)}%. Pipe 2: ${secondPipePercent.toFixed(2)}%.`);
  16.     } else {
  17.     console.log(`For ${hours.toFixed(2)} hours the pool overflows with ${totalFill - poolVolume} liters.`)
  18. }
  19. }
Add Comment
Please, Sign In to add comment