Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

171
Views
match objects then calculate grade for student grade

I'm stuck with a problem.

So i'm making this student grading system. The way it works is that the system should be able to match answer key with a student's answer. The answer keys are stored like this:

 const answerkeys = {math01: a, math02: b, math03 : d, ...}

There is also a grading system where math01 is worth 5 points, and math 02 worth 10 points, etc. Out of confusion, i saved the data in another set of data collection as something like this:

const scoring = {math01: 5, math02: 10, math03: 5, ...}

And then the students' answers are stored like this:

const answers = {0: {math01: a, math02: c, ... }
           1: {math01: b, math02: a, ... }
           2: {math01: a, math02: c, ... }
           ...
           }

At first, logically i thought i can iterate answers, then the individual result will be matched with answerkeys and the returned (matches) will then be multiplied with answerkeyandscore.

So i tried doing it this way:

const studentAnswers = answers.map((elem) => {return elem});

studentAnswer.filter(answer => answerkeys.includes(answer));

But it is giving me

"result.js:82 Uncaught TypeError: Cannot read properties of undefined (reading 'filter')"

How to compare between "answerkeys" and "answers" and then calculate the scores using "scoring"?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

There is no native map to the Object object, but i suggest this will works:

let allStudentsScores = {}

for (var idx in answers) {
    let studentAnswer = answers[idx]
    let studentScore = 0
    for(var key in studentAnswer) {
        if (studentAnswer[key]==answerkeys[key]) {
            studentScore += scoring[key]
        }

    }
    allStudentsScores[idx] = studentScore
}

the allStudentsScores variable contains each of student's score. Where the idx <0, 1, 2, ...> represents each student.

Hope answers your question.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!