JavaScript Contact manager help!!! | Sololearn: Learn to code for FREE!

+12

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();

12/13/2020 10:35:10 AM

TECH WORLD

54 Answers

New Answer

-19

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();

+49

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();

+16

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.

+9

๐•ž๐•’๐•™๐•š๐•ฃ ๐•’๐•“๐•š๐•• , 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();

+5

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 ๐Ÿฅณ๐Ÿฅณ๐Ÿฅณ๐Ÿฅณ๐Ÿฅณ

+4

This must be a code coach question, or something similar. This same question, with the exact same wording, and example data, keeps popping up regularly. ๐•ž๐•’๐•™๐•š๐•ฃ ๐•’๐•“๐•š๐•• has not made any attempt at this question. The code posted is from the question, not theirs, with the exception of the single line "print()". It even has the same class name in lower case. The convention is to use uppercase for constructor functions. Hint: You need to look at objects and prototype functions.

+3

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(); Input No Input Your Output David:12345 Amy:987654321 Expected Output David: 12345 Amy: 987654321

+2

Coding Kitty , he didn't post it first.

+2

i edited it

+2

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...

+2

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();

+1

yes i just copied!

+1

function contact(name, number) { this.name = name; this.number = number; this.print=function(){ console.log( this.name + ": "+ this.number); } }

+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();

+1

Easiest method of solving this problem is: Work 100% function contact(name, number) { this.name = name; this.number = number; //just tell console to do it no matter how many contacts are present in contact list console.log(this.name +": "+ this.number) } var a = new contact("David", 12345); var b = new contact("Amy", 987654321)

+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);

+1

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();

+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)

+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.

+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();