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);