if you need to return an average score for a given subject, shouldn't you be storing all individual results for a given subject, inside the the student dict?

currently it looks like there's just a single total for each subject...

setting that aside, here's a quick and dirty start...

function doStuff(student_name, target_subject, result){

// iterate over students

for (const [key, student] of Object.entries(students)) {

// find the relevant student, by name

if(student["name"] == student_name){

// iterate over students subjects

for (const [subject, score] of Object.entries(student["results"])) {

// find the target subject

if(subject == target_subject){

// record result

// calculate & return average

}

}

}

}

}

doStuff("Emily", "maths", 75);

Reply to this note

Please Login to reply.

Discussion

this might work, if the results value stored for each subject is already cumulative average ...