What am I doing wrong here in the code? It's not showing any output | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

What am I doing wrong here in the code? It's not showing any output

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. My code:. function contact(name, number) { this.name = name; this.number = number; this.print = function (anyName,anyNumber) { this.name = anyName; this.number = anyNumber ; document.write(anyName+ ": " +anyNumber ); } } var a = new contact("David", 12345); var b = new contact("Amy", 987654321); a.print(); b.print();

28th Oct 2021, 10:25 PM
Rubayet Kamal
Rubayet Kamal - avatar
6 Answers
+ 1
Your print method wants 2 arguments but you entered 0 a.print("new Name", 123456);
28th Oct 2021, 10:45 PM
Stefanoo
Stefanoo - avatar
0
Stefanoo I did this and still no output. function contact(name, number) { this.name = name; this.number = number; this.print = function (anyName,anyNumber) { this.name = anyName; this.number = anyNumber ; document.write(anyName+ ": "+ anyNumber ); } } var a = new contact("David", 12345); var b = new contact("Amy", 987654321); a.print("David", 12345); b.print("Amy", 987654321);
28th Oct 2021, 10:59 PM
Rubayet Kamal
Rubayet Kamal - avatar
0
Sanja Panic bro I simply followed the Topic the project is based on
28th Oct 2021, 11:01 PM
Rubayet Kamal
Rubayet Kamal - avatar
0
I deleted comment, because i checked and we can use function for this, class is added later. I checked your last code and i can see result.
28th Oct 2021, 11:03 PM
PanicS
PanicS - avatar
0
Sanja Panic Stefanoo thanks a lot but I have no idea why it was showing no output with document.write but did with console.log. Code////////// function contact(name, number) { this.name = name; this.number = number; this.print = function (anyName,anyNumber) { this.name = anyName; this.number = anyNumber ; console.log(anyName+ ": "+ anyNumber ); } } var a = new contact("David", 12345); var b = new contact("Amy", 987654321); a.print("David", 12345); b.print("Amy", 987654321);
28th Oct 2021, 11:06 PM
Rubayet Kamal
Rubayet Kamal - avatar
- 1
Anyways now it's working fine ,Thanks a lot a lot Stefanoo Sanja Panic
28th Oct 2021, 11:07 PM
Rubayet Kamal
Rubayet Kamal - avatar