Advertisement
desito07

PipesInPool

Apr 3rd, 2020
674
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.89 KB | None | 0 0
  1. function pipesInPool(input) {
  2. let volume = Number(input.shift());
  3. let p1 = Number(input.shift());
  4. let p2 = Number(input.shift());
  5. let hours = Number(input.shift());
  6.  
  7. let pipe1 = p1 * hours;
  8. let pipe2 = p2 * hours;
  9.  
  10. let pipePool = pipe1 + pipe2;
  11.  
  12. if (pipePool <= volume) {
  13. let poolPercent = (pipePool / volume) * 100;
  14. let p1Percent = (pipe1 / pipePool) * 100;
  15. let p2Percent = (pipe2 / pipePool) * 100;
  16. console.log(
  17. `The pool is ${poolPercent.toFixed(2)}% full. Pipe 1: ${p1Percent.toFixed(
  18. 2
  19. )}%. Pipe 2: ${p2Percent.toFixed(2)}%.`
  20. );
  21. } else if (pipePool > volume) {
  22. let overFlow = pipePool - volume;
  23. console.log(
  24. `For ${hours} hours the pool overflows with ${parseFloat(
  25. overFlow.toFixed(2)
  26. )} liters.`
  27. );
  28. }
  29. }
  30. pipesInPool(["1000", "100", "120", "3"]);
  31. pipesInPool(["100", "100", "100", "2.5"]);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement