I am having trouble calling a method inside of a constructor function I have made. Here is the function and my attempt to call it...
var Cohort = function(program, campus, number, students){
this.program = program,
this.campus = campus,
this.number = number,
this.students = students,
function sayName(){
return `This cohort is called ${program}, ${campus}, ${number}.`
},
function takeAttendance(){
return console.log(students)
}
}
var cohort1 = new Cohort("w", "pr", 27, ['devin', 'ben', 'bob'])
var cohort2 = new Cohort('w', 'pr', 31, ["Brendan Eich", "Dan Abramov", "Wes Bos", "Kent Dodds"])
cohort1.sayName()
the console is saying cohort1.sayName is not a function.
this.sayName = sayName;.this.program, the output ofsayNamewould not reflect it, right? In other words, I think what you posted would work, but I'm not sure it reflects the OP's intention (though who knows).