Contact Manager | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Contact Manager

You are working on a Contact Manager app. You have created the contact object constructor, which has two arguments, name and number. You need to add a print() method to the object, which will output the contact data to the console in the following format: name: number The given code declares two objects and calls their print() methods. Complete the code by defining the print() method for the objects. ___&___ mycode ___&___ function contact(name, number) { this.name = name; this.number = number; } var a = new contact("David", 12345); var b = new contact("Amy", 987654321); a.print(); b.print();

10th Feb 2022, 2:57 PM
Shai Shab
Shai Shab - avatar
1 Answer
+ 5
function contact(name, number) { this.name = name; this.number = number; this.print = () => { console.log(this.name + ": " + this.number); }; } var a = new contact("David", 12345); var b = new contact("Amy", 987654321); a.print(); b.print();
10th Feb 2022, 3:12 PM
SUJAN
SUJAN - avatar