Please help, JavaScript problem | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

Please help, JavaScript problem

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.

11th Dec 2020, 10:34 AM
Ozodbek Juraev
Ozodbek Juraev - avatar
8 Answers
+ 2
function contact(name, number) { this.name = name; this.number = number; this.print = function (name,number){ console.log(name,number); } } var a = new contact("David", 12345); var b = new contact("Amy", 987654321); a.print(a.name+':',a.number); b.print(b.name+':',b.number);
11th Dec 2020, 6:58 PM
Václav Dostál
Václav Dostál - avatar
+ 1
Thanks a lot
11th Dec 2020, 7:49 PM
Ozodbek Juraev
Ozodbek Juraev - avatar
0
If you solve words task, you can write me solution
11th Dec 2020, 6:59 PM
Václav Dostál
Václav Dostál - avatar
0
The Answer is: function contact(name, number) { this.name = name; this.number = number; this.print = function (name,number){ console.log(name,number); } } var a = new contact("David", 12345); var b = new contact("Amy", 987654321); a.print(a.name+':',a.number); b.print(b.name+':',b.number);
10th Mar 2021, 4:51 AM
Devansh Ojha
Devansh Ojha - avatar
0
Getting undefined for name any help?
22nd Mar 2021, 6:58 AM
Vaibhav Srivastava
Vaibhav Srivastava - avatar
0
function contact(name, number) { this.name = name; this.number = number; this.print= function (x, y){ console.log(x,y)}; } var a = new contact("David", 12345); var b = new contact("Amy", 987654321); a.print(a.name+':',a.number); b.print(b.name+':',b.number);
16th Apr 2021, 11:05 AM
Ahmed Hani Tbakhi
Ahmed Hani Tbakhi - avatar
0
the above code show an undefined after each answer. david: 12345 undefined amy: 987654321 undefined
10th Aug 2021, 7:28 AM
Montu kumar
Montu kumar - avatar
0
function contact(name, number) { this.name = name; this.number = number; this.print=function (name,number) { console.log(name + ": " + number); } } var a = new contact("David", 12345); var b = new contact("Amy", 987654321); a.print(a.name,a.number); b.print(b.name,b.number);
6th Oct 2021, 11:26 AM
Oumayma Bayoudh
Oumayma Bayoudh - avatar