0
Contact Manager Program
Anyone please code the program of contact manager & explain about functions using objects. Thanks in advance
9 ответов
+ 1
What is contact manager program can you tell the task
+ 1
You’re working on a contact manager app.
You’ve 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
Code has to declare two objects and call their print() methods.
Write the code by defining the print() method for the objects.
+ 1
Yes, I’m trying but getting errors😌 please help!
+ 1
function main(){
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();
print = function(){
console.log(contact.name ": "contact.number);
}
}
0
Sana Bari have u done any code becz according to community rule i cannot tell you solution directly without your attempt
0
Ok just post your attempt here i will try to correct it
0
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();
0
You have defined function main but you not using anywhere in last console line u need to write+ for concatenation here u written ":" this is providing errors .
After that you have defined two variables when u will pass values it will call contact function value will be assigned to name and number . When your function () will call u should access data by using this not via contact.name