試圖弄清楚如何將在文本區域中輸入的所有字母成績分配到新數組,將字母與點匹配並計算成績點。就像在這個例子中一樣,如何計算totalGradePoints。 HTML部分被剪切。任何幫助表示讚賞。無法計算出如何計算成績點
<html>
<!-- gpa2.html -->
<html>
<head>
<title>GPA</title>
</head>
<script type="text/javascript">
//Assigning grades to match points
var grades = ['A', 'B+', 'B', 'C+', 'C', 'D', 'F', 'AF', 'WF'],
points = [4, 3.5, 3, 2.5, 2, 1, 0, 0, 0];
function getData() {
var input = 0,
results = [];
input = document.getElementById("inputs").value.split("\n");
for (var i = 0; i < input.length; i++) {
input[i] = input[i].split(" ");
results.push({
course: input[i][0].trim(),
grade: input[i][1].trim,
creditHours: parseInt(input[i][2], 10)
});
}
return results;
}
//GPA calculation
var output = function() {
var results,
totalCreditHours = 0,
totalGradePoints = 0,
gpa = 0;
results = getData();
for (i = 0, j = results.length; i < j; i++) {
totalCreditHours += results[i].creditHours;
}
gpa = (totalCreditHours === 0 ? 0 : totalGradePoints/totalCreditHours).toFixed(3);
var output1 = document.getElementById("totalGradePointsOutput");
output1.value = totalGradePoints
var output2 = document.getElementById("totalCreditHours");
output2.value = totalCreditHours
var output3 = document.getElementById("gpaOut");
output3.value = gpa
}
</script>
<body>
</body>
</html>
看起來像功課。 –
@Derek這是HW的一部分,相關性如何? –
大部分時間這樣的作業問題不夠具體,不包括任何嘗試的問題將被關閉。 –