// 定义学生数组,每个对象包含姓名及各科成绩
const students = [
{ name: '学生1', chinese: 80, math: 90, english: 70 },
{ name: '学生2', chinese: 85, math: 95, english: 75 },
{ name: '学生3', chinese: 90, math: 100, english: 80 }
];
// 遍历学生数组,计算并展示各科成绩和总成绩
students.forEach(student => {
// 计算总成绩(语文+数学+英语)
const total = student.chinese + student.math + student.english;
// 格式化输出信息
console.log(`${student.name}的成绩:` +
`语文${student.chinese}分,` +
`数学${student.math}分,` +
`英语${student.english}分,` +
`总成绩${total}分`);
});