Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function solve(volume, p1, p2, hours) {
- volume = Number(volume);
- p1 = Number(p1);
- p2 = Number(p2);
- hours = Number(hours);
- let pipe1 = p1 * hours;
- let pipe2 = p2 * hours;
- let totalLiters = pipe1 + pipe2;
- if (totalLiters < volume) {
- let percentLiters = (totalLiters / volume * 100).toFixed(2);
- let percentP1 = ((pipe1 / totalLiters) * 100).toFixed(2);
- let percentP2 = ((pipe2 / totalLiters) * 100).toFixed(2);
- console.log(`The pool is ${percentLiters}% full. Pipe 1: ${percentP1}%. Pipe 2: ${percentP2}%.`)
- } else if (totalLiters > volume) {
- let overflowing = totalLiters - volume;
- console.log(`For ${hours.toFixed(2)} hours the pool overflows with ${overflowing.toFixed(2)} liters.`);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement