AreWe

Grades (interesting)

Jun 12th, 2020
1,224
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. grades = (score) => {
  2.     /*
  3.     let grade = 'Excellent';
  4.     if(score < 3.00) grade = 'Fail';
  5.     else if(score < 3.50) grade = 'Poor';
  6.     else if(score < 4.50) grade = 'Good';
  7.     else if(score < 5.50) grade = 'Very good';
  8.     console.log(grade);
  9.     //*/
  10.  
  11.     ///*
  12.     // const grades = [ undefined, undefined, 'Fail', 'Poor', 'Good', 'Very good', 'Excellent' ];
  13.     const grades = { 2: 'Fail', 3: 'Poor', 4: 'Good', 5: 'Very good', 6: 'Excellent' };
  14.     const int = Math.trunc(score), fract = score - int;
  15.     const grade = int + (fract >= 0.5 && int !== 2 ? 1 : 0);
  16.  
  17.     console.log(grades[grade]);
  18.     //*/
  19. };
Advertisement
Add Comment
Please, Sign In to add comment