constobjProto={fullName:function(){returnthis.firstName+" "+this.lastName;},};constobj1={firstName:"John",lastName:"Doe",age:50,};Object.setPrototypeOf(obj1,objProto);console.log(obj1.fullName());// John Doe
conststudent={firstName:"John",lastName:"Doe",scores:[],average:0,total:0,addScore:function(score){this.scores.push(score);returnthis;// will return the object itself, making the chaining possible},calculateAverage:function(){this.calculateTotal();this.average=this.total/this.scores.length;returnthis;},calculateTotal:function(){this.total=0;for(leti=0;i<this.scores.length;i++){this.total+=this.scores[i];}returnthis;},print:function(){console.log(this.firstName+" "+this.lastName+" average: "+this.average+" total: "+this.total);},};student.addScore(10).addScore(20).addScore(30).calculateAverage().calculateTotal().print();console.log({student});