1
该代码用于合计标记,计算平均值并确定学生是否合格/不合格。但是,它可以是一个正确的面向对象技术,它是否可以以更好的方式完成?面向对象OOJS
function Student(marks1, marks2, marks3, marks4, marks5, marks6) {
// To find the sum total of the marks obtained
var sum = 0;
for (var i = 0; i < arguments.length; i++) {
sum += arguments[i];
}
alert(" Total Marks is " + sum);
console.log(" Total Marks is " + sum);
// To find the average of the marks
var average = sum/6;
alert(" Average Marks is " + average);
console.log(" Average Marks is " + average);
// To check if the student has passed/failed
if (average > 60) {
alert("Student has passed the exam");
console.log("Student has passed the exam");
} else {
alert("Student has failed the exam");
console.log("Student has failed the exam");
}
}
var myStudent = new Student(58, 64, 78, 65, 66, 58);