Advertisement
Spocoman

Online Education

Sep 23rd, 2023 (edited)
1,144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function onlineEducation(input) {
  2.     let onlineStudents = 0;
  3.     let onsiteStudents = 0;
  4.  
  5.     let educationForm;
  6.     let studentCount;
  7.  
  8.     for (let i = 0; i < 6; i += 2) {
  9.         educationForm = input[i].toLowerCase();
  10.         studentCount = Number(input[i + 1]);
  11.  
  12.         if (educationForm === "online") {
  13.             onlineStudents += studentCount;
  14.         } else {
  15.             onsiteStudents += studentCount;
  16.         }
  17.     }
  18.  
  19.     if (onsiteStudents > 600) {
  20.         onlineStudents += onsiteStudents - 600;
  21.         onsiteStudents = 600;
  22.     }
  23.  
  24.     console.log(`Online students: ${onlineStudents}`);
  25.     console.log(`Onsite students: ${onsiteStudents}`);
  26.     console.log(`Total students: ${onlineStudents + onsiteStudents}`);
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement