+ 21

JavaScript Contact manager help!!!

please help me to solve it.. 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. code__ 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();

13th Dec 2020, 10:35 AM
TECH WORLD
TECH WORLD - avatar
99 odpowiedzi
- 77
please help me to solve it.. 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. code__ 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();
13th Jan 2021, 4:37 AM
jose-cardozo
+ 134
One of the correct ways is: function contact(name, number) { this.name = name; this.number = number; this.print = print; } function print() { console.log(this.name + ": " + this.number); } var a = new contact("David", 12345); var b = new contact("Amy", 987654321) a.print(); b.print();
15th Jan 2021, 8:42 PM
Cristhian Martinez Lara
Cristhian Martinez Lara - avatar
+ 43
function 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(); This worked for me.
6th Jan 2021, 7:28 AM
Anandhu S Nair
Anandhu S Nair - avatar
+ 16
𝕞𝕒𝕙𝕚𝕣 𝕒𝕓𝕚𝕕 , where did you use print() method, it's empty. It should print formatted text separated by ": ". For example you can do it this way: 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();
13th Dec 2020, 10:45 AM
TheWh¡teCat 🇧🇬
TheWh¡teCat 🇧🇬 - avatar
+ 10
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(); can any one help me where the mistake I have done.i am not getting this 🤔🤔🤔🤔 I am getting the output David : 12345 Amy : 987654321 But the original output is David: 12345 Amy: 987654321 Hey guys I got it we should only use the space after name+" and we should not use space between :" before number. means name+" :"+number . Finally I did it 🥳🥳🥳🥳🥳
24th Jan 2021, 4:18 AM
Ruthala Ushasri
+ 6
function contact(name, number) { this.name = name; this.number = number; this.print=function(){ console.log(this.name+": "+this.number); } } var a = new contact("David", 12345); var b = new contact("Amy", 987654321) a.print(); b.print(); Try this it will work. Most of you made a mistake by not adding space after : (colon) in the console log...
28th Jan 2021, 3:49 AM
Aashik
+ 4
function contact (name, number) { this.name = name; this.number =number; this.print =print1; } function print1() { return console.log(this.name +":" ,this.number); } var a = new contact ("David", 12345); var b = new contact("Amy", 98654321); a.print(); b.print();
7th Jun 2021, 4:15 PM
sarah
sarah - avatar
+ 3
function contact(name, number) { this.name = name; this.number = number; this.print = output; } function output(){ console.log(this.name +": "+ this.number ); } var a = new contact("David", 12345); var b = new contact("Amy", 987654321); a.print(); b.print();
13th Mar 2022, 7:21 AM
Olufikayomi Jetawo
+ 2
function contact(name, number) { this.name = name; this.number = number; this.print=print; } function print(){ console.log(this.name+": "+this.number); } var a = new contact("David", 12345); var b = new contact("Amy", 987654321); a.print(); b.print();
9th Jul 2021, 12:42 AM
Mohammad Dagher
Mohammad Dagher - avatar
+ 2
function contact(name, number) { this.name = name; this.number = number; this.print = print; } function print() { console.log(this.name + ": " + this.number); } var a = new contact("David", 12345); var b = new contact("Amy", 987654321) a.print(); b.print(); Good Luck
13th Dec 2021, 2:13 AM
Muhammad Alif Deva Rizqon
Muhammad Alif Deva Rizqon - avatar
+ 1
Coding Kitty , he didn't post it first.
13th Dec 2020, 10:42 AM
TheWh¡teCat 🇧🇬
TheWh¡teCat 🇧🇬 - avatar
+ 1
function contact(name, number) { this.name = name; this.number = number; } var a = new contact("David", 12345); var b = new contact("Amy", 987654321); console.log(a.name + ":"+" " + a.number); console.log(b.name+ ":" + " " +b.number);
15th Mar 2021, 1:59 PM
SHUBHAM RAMESH NIMJE
SHUBHAM RAMESH NIMJE - avatar
+ 1
I know i doesn't use print method here but it works fine. function contact(name, number) { this.name = name; this.number = number; } var a = new contact("David", 12345); var b = new contact("Amy", 987654321); console.log(a.name+": "+a.number) console.log(b.name+": "+b.number)
7th Apr 2021, 6:23 AM
Murtuza Rangwala
Murtuza Rangwala - avatar
+ 1
function contact(name, number) { this.name = name; this.number = number; this.print = print; function print() { 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(); // I tried this and it worked for me.
21st May 2021, 8:03 PM
Adebisi Ola-Adebomi
+ 1
function contact(name, number) { this.name = name; this.number = number; this.print = print1; } function print1(){ return console.log(this.name + ": " + this.number); } var a = new contact("David", 12345); var b = new contact("Amy", 987654321); a.print(); b.print();
29th May 2021, 3:02 PM
new name
new name - avatar
+ 1
Function print() { Console.log(this.name+":"+this.number); }
10th Jun 2021, 2:08 PM
Mahsa Baniasad Askari
+ 1
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(); This was the shortest code I could do for this
11th Aug 2021, 9:50 AM
Piyush Gandhi
Piyush Gandhi - avatar
+ 1
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();
14th Aug 2021, 2:01 PM
HongKyu Lim
HongKyu Lim - avatar
+ 1
function contact(name, number) { this.name = name; this.number = number; this.print = function (){ console.log(this.name + ':' + ' ' + this.number) } } var a = new contact("David", 12345); var b = new contact("Amy", 987654321); a.print(); b.print();
29th Aug 2021, 3:37 AM
Adeoye Paul
+ 1
function contact(name, number) { this.name = name; this.number = number; this.print = () => console.log(name + ': ' + number) } var a = new contact("David", 12345); var b = new contact("Amy", 987654321); a.print(); b.print(); Please always attempt a problem before looking for solutions going forward, it'll help you.
25th Nov 2021, 3:49 PM
Cornelius Ogunjeminiyi
Cornelius Ogunjeminiyi - avatar