Skip to content

Instantly share code, notes, and snippets.

@cem2ran
Last active Aug 29, 2015
Embed
What would you like to do?
Stads Average
var lines = document.getElementsByClassName('DataSelect');
var gradeCalc = {
grades: [],
average: -1,
weightedSum: 0,
ectsSum: 0
};
for(var i = 0; i < lines.length; i++){
var children = lines[i].children;
var grade = {};
for(var g = 0; g < children.length; g++){
var child = children[g];
switch(g){
case 0:
grade.title = child.textContent.replace(/^\s+|\s+$/g, '');
break;
case 1:
grade.date = child.textContent;
break;
case 2:
grade.grade = parseInt(child.textContent);
break;
case 3:
grade.ects_grade = child.textContent.replace(/^\s+|\s+$/g, '');
break;
case 4:
grade.ects = parseFloat(child.textContent);
break;
}
}
if(grade.ects_grade !== "Fx" && grade.ects_grade !== ""){
gradeCalc.weightedSum += (grade.grade * grade.ects);
gradeCalc.ectsSum += grade.ects;
}
gradeCalc.grades.push(grade);
}
gradeCalc.average = Math.round((gradeCalc.weightedSum / gradeCalc.ectsSum) * 100) / 100;
document.getElementById('leftbar').innerHTML = "<p>VÆGTET GENNEMSNIT:</p><h1>"+gradeCalc.average+"</h1>";
console.log(gradeCalc);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment