Javascript document.writeln显示)))

时间:2015-09-29 02:56:00

标签: javascript

我正在编写一个程序,提示用户输入测试成绩。等级将被转换为数组,然后使用if语句检查以添加到A,B,C,D或F的计数器数组。在语句添加之后,我使用document.writeln来显示代码到一张桌子。每当我运行代码时,屏幕会在显示表格之前显示三个)))。我无法弄清楚为什么会这样。

<!DOCTYPE html>
<html>
<head>
    <script>
        scores = prompt("Enter scores:");
        if (scores== null || scores == "")
        {
        document.writeln("No graph to display.");
        }
        else
            {
            scores = scores.split(" ");
            var grades = [0,0,0,0,0];
            for(i=0; i <= scores.length; i++)
            {
                if(scores[i] >= 90 && scores[i] <= 100)
                    grades[0]++;
                else if (scores[i] >= 80 && scores[i] < 90)
                    grades[1]++;
                else if (scores[i] >= 70 && scores[i] < 80)
                    grades[2]++;
                else if (scores[i] >= 60 && scores[i] < 70)
                    grades[3]++;
                else if (scores[i] >= 0 && scores[i] <60)
                    grades[4]++;

                }               
            document.writeln('<table> <tbody> <tr><td><div style="height:' + grades[0] * 20 + 'px"class="fill0"> </div></td>');
            document.writeln('<td><div style="height:' + grades[1] * 20 + 'px"class="fill1"> </div></td>');
            document.writeln('<td><div style="height:' + grades[2] * 20 + 'px"class="fill2"> </div></td>');
            document.writeln('<td><div style="height:' + grades[3] * 20 + 'px"class="fill3"> </div></td>');
            document.writeln('<td><div style="height:' + grades[4] * 20 + 'px"class="fill4"> </div></td> </tr>');
            document.writeln('<tr> <td> A </td>');
            document.writeln('<td> B </td>');
            document.writeln('<td> C </td>');
            document.writeln('<td> D </td>');
            document.writeln('<td> F </td> </tr>');
            document.writeln('<tr> <td>' + grades[0] + '</td>');
            document.writeln('<td>' + grades[1] + ' </td>)'); 
            document.writeln('<td>' + grades[2] + ' </td>)'); 
            document.writeln('<td>' + grades[3] + ' </td>)'); 
            document.writeln('<td>' + grades[4] + ' </td> </tr> </tbody> </table>'); 
            }
    </script>
    <style>
    .fill0 { background-color: rgb(0,0,100)}
    .fill1 {background-color: rgb(0,0,200)}
    .fill2 {background-color: rgb(0,0,150)}
    .fill3 {background-color: rgb(0,0,225)}
    .fill4 {background-color: rgb(0,0,50)}
    </style>
</head>
<body>
</body>
</html>

1 个答案:

答案 0 :(得分:2)

你在这里打印)

document.writeln('<td>' + grades[1] + ' </td>)'); 
document.writeln('<td>' + grades[2] + ' </td>)'); 
document.writeln('<td>' + grades[3] + ' </td>)');