+ 1

You are working on a Contact Manager app. You have created the contact object constructor, which has two arguments, name andno.

4th Sep 2021, 6:31 PM
Srushti Hegnekar
23 Respostas
+ 5
You need to write a method called "print()" for the content object.
4th Sep 2021, 7:02 PM
Lisa
Lisa - avatar
+ 4
//Modified your code hope it will work fine 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();
4th Sep 2021, 7:15 PM
A S Raghuvanshi
A S Raghuvanshi - avatar
+ 4
Use this, so you can solve the problem. function contact(name, number) { this.name = name; this.number = number; this.print=function() { console.log(name+": "+number); } } var a = new contact("David", 12345); var b = new contact("Amy", 987654321); a.print(); b.print();
5th Sep 2021, 5:29 AM
Aarti Rani
Aarti Rani - avatar
+ 3
function contact(name, number) { this.name = name; this. number= number ; } This is c++ Function :-- šŸ“œ https://code.sololearn.com/c39N9RN6b4Md/?ref=app
6th Sep 2021, 9:03 AM
Shubham Bhatia
Shubham Bhatia - avatar
+ 2
Can you please put your code in a playground script and share the link so we can help you?
4th Sep 2021, 6:50 PM
Lisa
Lisa - avatar
+ 2
Yes, it shows error because there is no print method in contact. The task is to write it.
4th Sep 2021, 7:07 PM
Lisa
Lisa - avatar
+ 2
In order to make print() a method of contect, put it inside of contact with "this" ā€“ like they did with name and number
4th Sep 2021, 7:13 PM
Lisa
Lisa - avatar
+ 2
I don't know what you did, but check the code of A.S. : print() is a method of contact and console.log() prints name and number
4th Sep 2021, 7:18 PM
Lisa
Lisa - avatar
+ 1
Hi, this is the Q&A section. You can ask programming related questions here. What is your question?
4th Sep 2021, 6:37 PM
Lisa
Lisa - avatar
+ 1
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();
4th Sep 2021, 6:52 PM
Srushti Hegnekar
+ 1
But it's showing an error
4th Sep 2021, 7:05 PM
Srushti Hegnekar
+ 1
In the code snippet you shared there's no print. If you changed it, share the current code: Put it in a playground script!
4th Sep 2021, 7:10 PM
Lisa
Lisa - avatar
+ 1
Can you please put your code in a playground script?
4th Sep 2021, 7:10 PM
Srushti Hegnekar
+ 1
function contact(name,number) { this.name = name; this.number = number; } print() var a = new contact("David", 12345); var b = new contact("Amy", 987654321) a.print(); b.print();
4th Sep 2021, 7:12 PM
Srushti Hegnekar
+ 1
This is my current code
4th Sep 2021, 7:12 PM
Srushti Hegnekar
+ 1
Thanks A.S.
4th Sep 2021, 7:19 PM
Srushti Hegnekar
+ 1
Hi man! try Aarty Rani code, its works.
5th Sep 2021, 7:07 PM
nanaxa
nanaxa - avatar
0
How solve this javascript program?
4th Sep 2021, 6:44 PM
Srushti Hegnekar
0
Can you please tell me what's gone wrong?
4th Sep 2021, 6:53 PM
Srushti Hegnekar
0
Lisa your method not working l had tried just now
4th Sep 2021, 7:17 PM
Srushti Hegnekar