+ 1
You are working on a Contact Manager app. You have created the contact object constructor, which has two arguments, name andno.
23 Antworten
+ 5
You need to write a method called "print()" for the content object.
+ 4
//Modified your code hope it will work fine
function contact(name, number) {
this.name = name;
this.number = number;
this.print = function contact(){
console.log(this.name+ ": " +this.number)
}
}
var a = new contact("David", 12345);
var b = new contact("Amy", 987654321)
a.print();
b.print();
+ 4
Use this, so you can solve the problem.
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();
+ 3
function contact(name, number) {
this.name = name;
this. number= number ;
}
This is c++ Function :-- 📜
https://code.sololearn.com/c39N9RN6b4Md/?ref=app
+ 2
Can you please put your code in a playground script and share the link so we can help you?
+ 2
Yes, it shows error because there is no print method in contact. The task is to write it.
+ 2
In order to make print() a method of contect, put it inside of contact with "this" – like they did with name and number
+ 2
I don't know what you did, but check the code of A.S. :
print() is a method of contact and console.log() prints name and number
+ 1
Hi, this is the Q&A section. You can ask programming related questions here. What is your question?
+ 1
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();
+ 1
But it's showing an error
+ 1
In the code snippet you shared there's no print. If you changed it, share the current code: Put it in a playground script!
+ 1
Can you please put your code in a playground script?
+ 1
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();
+ 1
This is my current code
+ 1
Thanks A.S.
+ 1
Hi man! try Aarty Rani code, its works.
0
How solve this javascript program?
0
Can you please tell me what's gone wrong?
0
Lisa your method not working l had tried just now