In my program, I'm getting grades from students using the and calculating their grade. to check what grade they get I have listed the grades data in a dictionary and I want to check if my grade is bigger than certain grade give them A if not it'll continue until it finds the proper grade. Thus, I have arranged my dictionary objects to be from highest grade to the lowest, so once it finds the proper grade stop and prints the grade to the user. for some reason it is looping from the lowest key object to the highest key, how would I fix that? to loop from the first key to the last no matter what's its value.
var dict = {94: '"It is, A, excellent"', 90: '"It is, A-, great job"', 87: '"It is, B+, great"', 84: "It is, B, amazing", 80: "It is, B-, study little more", 77: "It is, C+, you could do better", 74: "It is, C", 70: "It is, C-", 67: "Is your grade, D+"}
function gradeCheck(sum){
var tex;
Object.keys(dict).forEach( function(key){
//console.log(key, dict[key]);
/*if(sum>=key && (sum-key)<6 ){
tex = dict[key];
return tex;
}*/
if(sum > key){
tex = dict[key];
return tex;
}
});
}
I commented my old part code.
I hope someone can help, Thanks