Working calculateDegree function.