Advertisement
dancheff

Untitled

Mar 28th, 2020
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solve(volume, p1, p2, hours) {
  2.     volume = Number(volume);
  3.     p1 = Number(p1);
  4.     p2 = Number(p2);
  5.     hours = Number(hours);
  6.  
  7.     let pipe1 = p1 * hours;
  8.     let pipe2 = p2 * hours;
  9.  
  10.     let totalLiters = pipe1 + pipe2;
  11.  
  12.     if (totalLiters < volume) {
  13.         let percentLiters = (totalLiters / volume * 100).toFixed(2);
  14.         let percentP1 = ((pipe1 / totalLiters) * 100).toFixed(2);
  15.         let percentP2 = ((pipe2 / totalLiters) * 100).toFixed(2);
  16.         console.log(`The pool is ${percentLiters}% full. Pipe 1: ${percentP1}%. Pipe 2: ${percentP2}%.`)
  17.     } else if (totalLiters > volume) {
  18.         let overflowing = totalLiters - volume;
  19.         console.log(`For ${hours.toFixed(2)} hours the pool overflows with ${overflowing.toFixed(2)} liters.`);
  20.     }
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement