Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/470.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 将数据写入具有未知行数的表_Javascript - Fatal编程技术网

Javascript 将数据写入具有未知行数的表

Javascript 将数据写入具有未知行数的表,javascript,Javascript,我正在学习一门非常基础的“JS入门”课程,我对这个问题的解决需要同样基础和陈旧 这个练习应该显示一个带有标题的表格,标题中有学生姓名和得分在90分或以上的学生的分数。(数据来自另一个js文件。) 然后,它应该显示学生总数和得分为90分或以上的学生总数。我的math&if语句似乎在工作,但显示不是很好。任何帮助都将不胜感激 const ZERO = 0; const NINETY_PERCENT = 90; var studentName; var studentScore; var total

我正在学习一门非常基础的“JS入门”课程,我对这个问题的解决需要同样基础和陈旧

这个练习应该显示一个带有标题的表格,标题中有学生姓名和得分在90分或以上的学生的分数。(数据来自另一个js文件。)

然后,它应该显示学生总数和得分为90分或以上的学生总数。我的math&if语句似乎在工作,但显示不是很好。任何帮助都将不胜感激

const ZERO = 0;
const NINETY_PERCENT = 90;

var studentName;
var studentScore;
var totalStudents;
var totalStudentsWithAs;
var studentRecords;

studentRecords = openStudentExamRecords();

function initializeExamRecords() {
    totalStudents = ZERO;
    totalStudentsWithAs = ZERO;
}

function startTable() {
    document.write("<th>Student Name</th>");
    document.write("<th>Exam Score</th>");
}

function printRecords() {
    initializeExamRecords();
    startTable();
    while (studentRecords.readNextRecord()) {
        studentName = studentRecords.getStudentName();
        studentScore = studentRecords.getStudentScore();
        totalStudents++;

        if (studentScore >= NINETY_PERCENT) {
            document.write("</td><td>");
            document.write(studentName);
            document.write("</td><td>");
            document.write(studentScore);
            totalStudentsWithAs++;
            totalStudents = Number(totalStudents);
            totalStudentsWithAs = Number(totalStudentsWithAs); alert("");
        }
    }
}

function endTable() {
    document.write("</td></tr>");
}

function printTotals() {
    printRecords();
    document.write("</td><td>");
    document.write("<tr><td colspan='5'>&nbsp;</td></tr>");
    document.write("<tr><td colspan='5'>Total Students: <strong>" +
        totalStudents + "</strong></td></tr>");
    document.write("<tr><td colspan='5'>Total Sudents with A's: <strong>" +
        totalStudentsWithAs + "</strong></td></tr>");
    document.write("</td><tr>");
}

function endTable() {
    document.write("</td></tr>");
}

printTotals();
endTable();
constzero=0;
常数百分之九十=90;
var学生名;
var学生分数;
学生;
var totalStudentsWithAs;
var-studentRecords;
studentRecords=openStudentExamRecords();
函数初始化eExamRecords(){
学生总数=零;
学生总数为零;
}
函数startTable(){
文件。填写(“学生姓名”);
文件。书写(“考试分数”);
}
函数printRecords(){
初始化eexamrecords();
startTable();
while(studentRecords.readNextRecord()){
studentName=studentRecords.getStudentName();
studentScore=studentRecords.getStudentScore();
学生++;
如果(学生分数>=百分之九十){
文件。填写(“”);
文件。书写(学生姓名);
文件。填写(“”);
写作(学生分数);
学生总数为++;
学生总数=人数(学生总数);
totalStudentsWithAs=数字(totalStudentsWithAs);警报(“”);
}
}
}
函数结束表(){
文件。填写(“”);
}
函数printTotals(){
打印记录();
文件。填写(“”);
文件。填写(“”);
记录。写下(“学生总数:”+
学生总数+“”;
文档。写下(“带A的总数:”+
学生总数为+“”;
文件。填写(“”);
}
函数结束表(){
文件。填写(“”);
}
printTotals();
endTable();

为什么,为什么JavaScript讲师继续教学生
document.write()
?!您有两个相同的函数,称为
endTable
@ScottMarcus,因为做任何其他事情都需要它们教给学生DOM,这可能会在初学者的课堂上造成灾难。endTable()应该只是在所有学生的名字和分数超过90%后停止将行添加到表中。还是不知道怎么做。Instrux:这个函数将输出一个HTML表尾标记。@Tomalak我做IT培训师已经20年了。在介绍中教授DOM基础知识。上课没什么大不了的。进入完整的DOM API是留待以后的。为什么JavaScript讲师继续教学生
document.write()
?!您有两个相同的函数,称为
endTable
@ScottMarcus,因为做任何其他事情都需要它们教给学生DOM,这可能会在初学者的课堂上造成灾难。endTable()应该只是在所有学生的名字和分数超过90%后停止将行添加到表中。还是不知道怎么做。Instrux:这个函数将输出一个HTML表尾标记。@Tomalak我做IT培训师已经20年了。在介绍中教授DOM基础知识。上课没什么大不了的。进入完整的domapi将留待以后使用。