Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function juiceDiet(input) {
- let r = Number(input[0]);
- let s = Number(input[1]);
- let c = Number(input[2]);
- let maxJuice = Number(input[3]);
- let juice = 0, raspberries = 0, strawberries = 0, cherries = 0;
- for (let j = 0; j <= r; j++) {
- for (let k = 0; k <= s; k++) {
- for (let l = 0; l <= c; l++) {
- let currentJuice = 4.5 * j + 7.5 * k + 15 * l;
- if (juice < currentJuice && currentJuice <= maxJuice) {
- juice = currentJuice;
- raspberries = j;
- strawberries = k;
- cherries = l;
- }
- }
- }
- }
- console.log(`${raspberries} Raspberries, ${strawberries} Strawberries, ${cherries} Cherries. Juice: ${juice} ml.`);
- return;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement