+ 21
JavaScript Contact manager help!!!
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. code__ 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();
101 ответ
- 77
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.
code__
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();
+ 134
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();
+ 43
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();
This worked for me.
+ 16
𝕞𝕒𝕙𝕚𝕣 𝕒𝕓𝕚𝕕 , where did you use print() method, it's empty. It should print formatted text separated by ": ". For example you can do it this way:
function contact(name, number) {
this.name = name;
this.number = number;
this.print = () =>{
console.log(this.name+": "+this.number);
}
}
var a = new contact("David", 12345);
var b = new contact("Amy", 987654321)
a.print();
b.print();
+ 10
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();
can any one help me where the mistake I have done.i am not getting this 🤔🤔🤔🤔
I am getting the output
David : 12345
Amy : 987654321
But the original output is
David: 12345
Amy: 987654321
Hey guys I got it
we should only use the space after name+"
and we should not use space between :" before number.
means name+" :"+number .
Finally I did it 🥳🥳🥳🥳🥳
+ 6
function contact(name, number) {
this.name = name;
this.number = number;
this.print=function(){
console.log(this.name+": "+this.number);
}
}
var a = new contact("David", 12345);
var b = new contact("Amy", 987654321)
a.print();
b.print();
Try this it will work. Most of you made a mistake by not adding space after : (colon) in the console log...
+ 4
function contact (name, number)
{
this.name = name;
this.number =number;
this.print =print1;
}
function print1()
{
return console.log(this.name +":" ,this.number);
}
var a = new contact ("David", 12345);
var b = new contact("Amy", 98654321);
a.print();
b.print();
+ 3
function contact(name, number) {
this.name = name;
this.number = number;
this.print = output;
}
function output(){
console.log(this.name +": "+ this.number );
}
var a = new contact("David", 12345);
var b = new contact("Amy", 987654321);
a.print();
b.print();
+ 2
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();
+ 2
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();
Good Luck
+ 1
Coding Kitty , he didn't post it first.
+ 1
function contact(name, number) {
this.name = name;
this.number = number;
}
var a = new contact("David", 12345);
var b = new contact("Amy", 987654321);
console.log(a.name + ":"+" " + a.number);
console.log(b.name+ ":" + " " +b.number);
+ 1
I know i doesn't use print method here but it works fine.
function contact(name, number)
{
this.name = name;
this.number = number;
}
var a = new contact("David", 12345);
var b = new contact("Amy", 987654321);
console.log(a.name+": "+a.number)
console.log(b.name+": "+b.number)
+ 1
function contact(name, number) {
this.name = name;
this.number = number;
this.print = print;
function print() {
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();
// I tried this and it worked for me.
+ 1
function contact(name, number) {
this.name = name;
this.number = number;
this.print = print1;
}
function print1(){
return console.log(this.name + ": " + this.number);
}
var a = new contact("David", 12345);
var b = new contact("Amy", 987654321);
a.print();
b.print();
+ 1
Function print()
{
Console.log(this.name+":"+this.number);
}
+ 1
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();
This was the shortest code I could do for this
+ 1
function contact(name, number) {
this.name = name;
this.number = number;
this.print = () => console.log(`${this.name}: ${this.number}`);
}
var a = new contact("David", 12345);
var b = new contact("Amy", 987654321);
a.print();
b.print();
+ 1
function contact(name, number) {
this.name = name;
this.number = number;
this.print = function (){
console.log(this.name + ':' + ' ' + this.number)
}
}
var a = new contact("David", 12345);
var b = new contact("Amy", 987654321);
a.print();
b.print();
+ 1
function contact(name, number) {
this.name = name;
this.number = number;
this.print = () => console.log(name + ': ' + number)
}
var a = new contact("David", 12345);
var b = new contact("Amy", 987654321);
a.print();
b.print();
Please always attempt a problem before looking for solutions going forward, it'll help you.