Advertisement
Spocoman

Credit System

Sep 23rd, 2023 (edited)
1,177
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function creditSystem(input) {
  2.     let n = Number(input[0]);
  3.    
  4.     let totalGrades = 0.0;
  5.     let totalCredits = 0.0;
  6.  
  7.     for (let i = 1; i <= n; i++) {
  8.         let number = Number(input[i]);
  9.         let grade = number % 10;
  10.         let credit = parseInt(number / 10);
  11.  
  12.         totalGrades += grade;
  13.  
  14.         if (grade == 2) {
  15.             credit = 0;
  16.         } else if (grade == 3) {
  17.             credit *= 0.50;
  18.         } else if (grade == 4) {
  19.             credit *= 0.70;
  20.         } else if (grade == 5) {
  21.             credit *= 0.85;
  22.         }
  23.  
  24.         totalCredits += credit;
  25.     }
  26.  
  27.     console.log(`${totalCredits.toFixed(2)}\n${(totalGrades / n).toFixed(2)}`);
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement