please help me to solve it.. | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

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. 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 Feb 2023, 4:30 PM
Prateek kumawat
Prateek kumawat - avatar
4 Answers
+ 1
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();
4th Feb 2023, 4:31 PM
Prateek kumawat
Prateek kumawat - avatar
+ 1
Prateek kumawat Have a look here.. Use this... this.print = function print(){ ........ }} Instead of... This.print=print{... }
4th Feb 2023, 4:42 PM
Darpan kesharwani🇮🇳[Inactive📚]
Darpan kesharwani🇮🇳[Inactive📚] - avatar
0
Define a method for the print object inside the object constructor. function contact(name, number) { this.name = name; this.number = number; this.print = function (printing){ console.log(this.name + ": " + this.number) } } this.print will then be associated with a.print() b.print()
5th Feb 2023, 9:40 PM
Keren Maidariya Aywila
0
Idk javascript
6th Feb 2023, 4:03 AM
Gabo Guzman
Gabo Guzman - avatar