Advertisement
Liliana797979

division without remainder

Feb 3rd, 2021
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function divisionWithoutRemainder(input) {
  2.     let n = Number(input[0]);
  3.  
  4.     p1 = 0;
  5.     p2 = 0;
  6.     p3 = 0;
  7.  
  8.     p1percentage = 0;
  9.     p2percentage = 0;
  10.     p3percentage = 0;
  11.    
  12.     for (let i = 1; i <= n; i++) {
  13.         let currentNum = Number(input[i]);
  14.         if (currentNum % 2 === 0) {
  15.             p1++;
  16.         } else if (currentNum % 3 ===0) {
  17.             p2++;
  18.         } else if (currentNum % 4 === 0) {
  19.             p3++;
  20.         }
  21.         p1percentage = (p1 / n * 100).toFixed(2);
  22.         p2percentage = (p2 / n * 100).toFixed(2);
  23.         p3percentage = (p3 / n * 100).toFixed(2);
  24.  
  25.     }
  26.     console.log(p1percentage + "%");
  27.     console.log(p2percentage + "%");
  28.     console.log(p3percentage + "%");
  29.  
  30. }
  31.  
  32. divisionWithoutRemainder(["3", "3", "6", "9"]);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement