Hey everyone, can anyone tell me why this constructor function isn’t working out. (I’m getting an undefined for avgGrade). As far as I understand the variable name that holds the value of the property that i’m defining in the contructor function can be anyname, yet this script doesn’t work…
As always, thanks in advance!
var yourName = window.prompt(“What’s your name?” , “”);
var yourAge = window.prompt(“What’s your age?” , “”);
var yourGrade = window.prompt(“What’s your G.P.A?” , “”);
var yourSex = window.prompt(“What’s your sex?” , “”);
function student(name,age,avgGrade,sex){
this.name = name;
this.age = age;
this.grade = avgGrade;
this.sex = sex;
}
var student1 = new student(yourName, yourAge, yourGrade, yourSex)
document.write(student1.avgGrade)