<!doctype html>
task6.3
<br> table, th, td{<br> border: solid 1px #000000;</p> <pre><code> } th{ text-align: left; } </style> </code></pre> <p></head></p> <p><body><br> <h1>List of Name, Score and Grade</h1><br> <p>Here is the list of student name, score and grade:</p></p> <pre><code> <div id="display"></div> <script type="text/javascript"> window.onload = function() { var student, outputText, nLength, n, score, sLength, i, grade; //all the student student = ['Mary', 'Jim', 'Albert', 'Carroll', 'Francis', 'Michael', 'John', 'Tim', 'Carlos', 'Steven']; score = [65, 70, 85, 90, 50, 62, 76, 88, 64, 45]; sLength = score.length; outputText = "<table>"; outputText += "<tr>"; outputText += "<th>" +"Name" +"</th>"; outputText += "<th>" +"Score" +"</th>"; outputText += "<th>" +"Grade" +"</th>"; outputText += "</tr>"; for (i = 0, n=0; i < sLength; i++, n++) { outputText += "<tr>"; outputText += "<td>"; outputText += student[n]; outputText += "</td>"; outputText += "<td>" + score[i] + "</td>"; outputText += "<td>"; if (score[i]>=80) { grade = "HD(High Distinction)"; } else if(score[i]<80 & score[i]>=70) { grade = "D(Distinction)"; } else if(score[i]<70 & score[i]>=60) { grade = "C(Credit)"; } else if(score[i]<60 & score[i]>=50) { grade = "P(Pass)"; } else { grade = "F(Failed)"; } outputText += grade; outputText += "</td>"; outputText += "</tr>"; } outputText += "</table>"; document.getElementById("display").innerHTML = outputText; } </script> </code></pre> <p></body><br> </html></p> <p>如何将中间if部分变成一个function。</p>