bacco

Grades

Mar 19th, 2018
246
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function number(inputData){
  2.     var n = Number(inputData[0]);
  3.  
  4.         var top =  0;
  5.         var verGood =  0;
  6.         var good =  0;
  7.         var fall =  0;
  8.         var all =  0;
  9.  
  10.     for(var i = 1; i <= n; i++) {
  11.        
  12.         var scores = Number(inputData[i]);
  13.         all += scores;
  14.        
  15.         if (scores > 4.99){
  16.             top ++;
  17.         } else if (scores > 3.99){
  18.             verGood ++;
  19.         } else if (scores > 2.99){
  20.             good ++;
  21.         } else
  22.            fall ++;
  23.         }
  24.         console.log(`Top students: ${(top / n * 100).toFixed(2)}%`);
  25.         console.log(`Between 4.00 and 4.99: ${(verGood / n * 100).toFixed(2)}%`);
  26.         console.log(`Between 3.00 and 3.99: ${(good / n * 100).toFixed(2)}%`);
  27.         console.log(`Fail: ${(fall / n * 100).toFixed(2)}%`);
  28.         console.log(`Average: ${(all / n).toFixed(2)}`);
  29.     }
  30.  
  31. number(["10", "3.00", "2.99", "5.68", "3.01", "4", "4", "6", "4.50", "2.44", "5"])
Advertisement
Add Comment
Please, Sign In to add comment