Advertisement
Spocoman

Juice Diet

Oct 9th, 2023
907
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function juiceDiet(input) {
  2.     let r = Number(input[0]);
  3.     let s = Number(input[1]);
  4.     let c = Number(input[2]);
  5.     let maxJuice = Number(input[3]);
  6.  
  7.     let juice = 0, raspberries = 0, strawberries = 0, cherries = 0;
  8.  
  9.     for (let j = 0; j <= r; j++) {
  10.         for (let k = 0; k <= s; k++) {
  11.             for (let l = 0; l <= c; l++) {
  12.                 let currentJuice = 4.5 * j + 7.5 * k + 15 * l;
  13.                 if (juice < currentJuice && currentJuice <= maxJuice) {
  14.                     juice = currentJuice;
  15.                     raspberries = j;
  16.                     strawberries = k;
  17.                     cherries = l;
  18.                 }
  19.             }
  20.         }
  21.     }
  22.  
  23.     console.log(`${raspberries} Raspberries, ${strawberries} Strawberries, ${cherries} Cherries. Juice: ${juice} ml.`);
  24.     return;
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement