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

Contact Manager Program

Anyone please code the program of contact manager & explain about functions using objects. Thanks in advance

31st Jul 2021, 4:58 PM
Sana Bari
Sana Bari - avatar
8 Answers
+ 1
What is contact manager program can you tell the task
31st Jul 2021, 5:05 PM
A S Raghuvanshi
A S Raghuvanshi - avatar
+ 1
You’re working on a contact manager app. You’ve 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 Code has to declare two objects and call their print() methods. Write the code by defining the print() method for the objects.
31st Jul 2021, 5:13 PM
Sana Bari
Sana Bari - avatar
+ 1
Yes, I’m trying but getting errors😌 please help!
31st Jul 2021, 5:16 PM
Sana Bari
Sana Bari - avatar
+ 1
function main(){ 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(); print = function(){ console.log(contact.name ": "contact.number); } }
31st Jul 2021, 6:40 PM
Sana Bari
Sana Bari - avatar
0
Sana Bari have u done any code becz according to community rule i cannot tell you solution directly without your attempt
31st Jul 2021, 5:15 PM
A S Raghuvanshi
A S Raghuvanshi - avatar
0
Ok just post your attempt here i will try to correct it
31st Jul 2021, 5:17 PM
A S Raghuvanshi
A S Raghuvanshi - avatar
0
function contact(name, number) { this.name = name; this.number = number; this.print = function contact(){ console.log(this.name+ ": " +this.number) } } var a = new contact("David", 12345); var b = new contact("Amy", 987654321) a.print(); b.print();
1st Aug 2021, 3:16 AM
A S Raghuvanshi
A S Raghuvanshi - avatar
0
You have defined function main but you not using anywhere in last console line u need to write+ for concatenation here u written ":" this is providing errors . After that you have defined two variables when u will pass values it will call contact function value will be assigned to name and number . When your function () will call u should access data by using this not via contact.name
1st Aug 2021, 3:21 AM
A S Raghuvanshi
A S Raghuvanshi - avatar