66 Answers
New Answerfunction contact(name, number) { this.name = name; this.number = number; this.print = function(){ var x = this.name var y = this.number console.log(x+":"+y) } } var a = new contact("David", 12345); var b = new contact("Amy", 987654321) a.print(); b.print();
2/7/2021 1:22:28 AM
Sathe Prerana Satish66 Answers
New AnswerI saw a bug that is, Constructor function is better with upper-case first letter.For example, 'Contact()' not 'contact()'. If not the code is correct.
function contact(name, number) { this.name = name; this.number = number; this.print=function(name,number){ console.log(this.name+': '+this.number); } } var a = new contact("David", 12345); var b = new contact("Amy", 987654321) a.print(); b.print();
this.name = name; this.number = number; this.print = function() { var x = this.name; var y = this.number; console.log(x+":"+y) } }
SoloLearn Inc.
4 Embarcadero Center, Suite 1455Send us a message