how to add elements to a constructor js code example
Example 1: javascript constructor function
function ClassMates(name,age){
this.name=name;
this.age=age;
this.displayInfo=function(){
return this.name + "is " + this.age + "year's old!";
}
}
let classmate1 = new ClassMates("Mike Will", 15);
classmate.displayInfo(); // "Mike Will is 15 year's old!"
Example 2: javascript constructor object
function Person(first, last, age, eye) {
this.firstName = first;
this.lastName = last;
this.age = age;
this.eyeColor = eye;
}