使用構造函數和原型,我希望Grade函數將數字等級輸出爲字母等級。Javascript原型
function Grade(name, grade) {
this.name = name;
}
Grade.prototype.grade = function(){
if(grade >= 90){return "A"}
else if (grade <90 && grade >=80){return "B"}
else if(grade <80 && grade >= 70) {return "C"}
else {return "fail"}
};
var sally = new Grade("Sally", 72);
console.log(sally.grade());
console.log(sally.name);
你從來沒有保存過'grade'值,使你的'grade'功能不能使用命名變量未定義的'grade' –