Last active
February 6, 2017 15:47
-
-
Save knowlet/b0994341f9ce1d1745212ba2d14c474c to your computer and use it in GitHub Desktop.
Calc TTU student's GPA.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// https://stucis.ttu.edu.tw/academic/ascoresbj.php | |
var regex = /^(\u62B5|\(?-?[0-9]{1,3}\)?)$/ | |
var totalPoints = 0; | |
var totalCredit = 0; | |
var nums = [].slice.call(document.querySelectorAll('td')) | |
.filter(function(e){ return regex.test(e.textContent); }) | |
.map(function(num, idx ,arr){ | |
var b = Number(num.innerHTML); | |
if (idx % 2 === 1) { | |
var a = Number(arr[idx-1].innerHTML); | |
var p; | |
if(b < 50) { | |
p = 0; | |
} else if(b < 60) { | |
p = 1; | |
} else if(b < 70) { | |
p = 2; | |
} else if(b < 80) { | |
p = 3; | |
} else { | |
p = 4; | |
} | |
totalCredit += a; | |
totalPoints += p * a; | |
} | |
return b; | |
}) | |
alert("Your GPA is : " + (totalPoints / totalCredit)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment