Advertisement
nerdforneurons

MHCET Marks calculator

May 23rd, 2024 (edited)
1,475
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Select all rows in the tbody of the table with id #tblObjection, skipping the first row
  2. const rows = document.querySelectorAll('#tblObjection > tbody > tr:nth-child(n+2)');
  3.  
  4. // Initialize counters for Physics, Chemistry, and Mathematics
  5. let correctAnswersPhysics = 0;
  6. let wrongAnswersPhysics = 0;
  7. let correctAnswersChemistry = 0;
  8. let wrongAnswersChemistry = 0;
  9. let correctAnswersMathematics = 0;
  10. let wrongAnswersMathematics = 0;
  11.  
  12. // Iterate through each row
  13. rows.forEach((row, index) => {
  14.     // Get the correct option and candidate response elements using the provided selectors
  15.     const correctOptionElement = row.querySelector('td:nth-child(3) > table.table.table-responsive.table-bordered.center > tbody > tr > td:nth-child(1) > span');
  16.     const candidateResponseElement = row.querySelector('td:nth-child(3) > table.table.table-responsive.table-bordered.center > tbody > tr > td:nth-child(2) > span');
  17.  
  18.     // Check if both elements exist
  19.     if (correctOptionElement && candidateResponseElement) {
  20.         const correctOption = correctOptionElement.textContent.trim();
  21.         const candidateResponse = candidateResponseElement.textContent.trim();
  22.  
  23.         // Determine the category based on the question index and compare answers
  24.         if (index < 50) {
  25.             // Physics
  26.             if (correctOption === candidateResponse) {
  27.                 correctAnswersPhysics++;
  28.             } else {
  29.                 wrongAnswersPhysics++;
  30.             }
  31.         } else if (index < 100) {
  32.             // Chemistry
  33.             if (correctOption === candidateResponse) {
  34.                 correctAnswersChemistry++;
  35.             } else {
  36.                 wrongAnswersChemistry++;
  37.             }
  38.         } else {
  39.             // Mathematics
  40.             if (correctOption === candidateResponse) {
  41.                 correctAnswersMathematics++;
  42.             } else {
  43.                 wrongAnswersMathematics++;
  44.             }
  45.         }
  46.     }
  47. });
  48.  
  49. // Calculate total score
  50. const totalScore = correctAnswersPhysics + correctAnswersChemistry + (correctAnswersMathematics * 2);
  51.  
  52. // Output the results
  53. console.log(`Physics - Correct Answers: ${correctAnswersPhysics}, Wrong Answers: ${wrongAnswersPhysics}`);
  54. console.log(`Chemistry - Correct Answers: ${correctAnswersChemistry}, Wrong Answers: ${wrongAnswersChemistry}`);
  55. console.log(`Mathematics - Correct Answers: ${correctAnswersMathematics}, Wrong Answers: ${wrongAnswersMathematics}`);
  56. console.log(`Total Score: ${totalScore} out of 200`);
  57.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement