Is it correct code? It's not working. | SoloLearn: Learn to code for FREE!

+12

Is it correct code? It's not working.

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

2/7/2021 1:22:28 AM

Sathe Prerana Satish

66 Answers

New Answer

+6

https://code.sololearn.com/Wgi02IExS7aX/?ref=app

+5

+5

I saw a bug that is, Constructor function is better with upper-case first letter.For example, 'Contact()' not 'contact()'. If not the code is correct.

+3

Ok I will try it

+2

Please explain

+2

Let me check here

+2

It works and output David:12345 Amy:987654321 what was the error message?

+2

The above program is working fine in my system. What type of error you are getting ??

+2

Yes it's correct now mark me as correct answer

+1

function contact(name, number) { this.name = name; this.number = number; this.print=function(name,number){ console.log(this.name+': '+this.number); } } var a = new contact("David", 12345); var b = new contact("Amy", 987654321) a.print(); b.print();

+1

I didn't understand

+1

I also declared it

+1

+1

+1

+1

Tell me if it works or not please.

+1

Waiting for ur reply.

+1

this.name = name; this.number = number; this.print = function() { var x = this.name; var y = this.number; console.log(x+":"+y) } }

+1

Just replace this one line only.

+1