Advertisement
Spocoman

Grandpa Stavri

Jan 6th, 2022 (edited)
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function grandpaStavri(input) {
  2.     let days = Number(input[0]);
  3.     let totalLiters = 0;
  4.     let averageGradus = 0;
  5.  
  6.     for (let i = 1; i <= days * 2; i++) {
  7.         let liters = Number(input[i++]);
  8.         let gradus = Number(input[i]);
  9.         totalLiters += liters;
  10.         averageGradus += liters * gradus;
  11.     }
  12.  
  13.     console.log(`Liter: ${totalLiters.toFixed(2)}`);
  14.     console.log(`Degrees: ${(averageGradus / totalLiters).toFixed(2)}`);
  15.     if (averageGradus < 38) {
  16.         console.log("Not good, you should baking!");
  17.     } else if (averageGradus <= 42) {
  18.         console.log("Super!");
  19.     } else {
  20.         console.log("Dilution with distilled water!");
  21.     }
  22. }
  23.  
  24. РЕШЕНИЕ СЪС SHIFT() И ТЕРНАРЕН ОПЕРАТОР:
  25.  
  26. function grandpaStavri(input) {
  27.     let days = Number(input.shift());
  28.     let totalLiters = 0;
  29.     let averageGradus = 0;
  30.    
  31.     for(let i = 0; i < days; i++) {
  32.         let liters = Number(input.shift());
  33.         let gradus = Number(input.shift());
  34.         totalLiters += liters;
  35.         averageGradus += liters * gradus;
  36.     }
  37.  
  38.     console.log(`Liter: ${totalLiters.toFixed(2)}`);
  39.     console.log(`Degrees: ${(averageGradus / totalLiters).toFixed(2)}`);
  40.     console.log( averageGradus < 38? "Not good, you should baking!" : averageGradus <= 42 ? "Super!" : "Dilution with distilled water!");
  41. }
  42.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement