+ 5

[Solved]JS Course

can you guys tell me what's the bug in this code?(JS Course Contact Manager project) function contact(name, number) { this.name = name; this.number = number; } function print(){ return this.name,this.number; } var a = new contact("David", 12345); var b = new contact("Amy", 987654321) a.print(); b.print();

30th Dec 2020, 3:16 PM
LordOfThunder [Inactive]
LordOfThunder [Inactive] - avatar
15 Réponses
+ 4
Add to contact function: this.print = print. Place a.print() and b.print() into console.log()
30th Dec 2020, 3:45 PM
speedprogame
speedprogame - avatar
+ 4
speedprogame thanks bro🤗
30th Dec 2020, 3:45 PM
LordOfThunder [Inactive]
LordOfThunder [Inactive] - avatar
+ 3
Alvaro Bastia No Problem I got the answer already🙃
29th Jan 2021, 5:51 PM
LordOfThunder [Inactive]
LordOfThunder [Inactive] - avatar
+ 2
Your print function has no object with name or number (this) which could refer to. So a) make print function method of the contact object (which is what you seem to have intended), or b) pass the contact object by parameter to the print function
30th Dec 2020, 3:27 PM
Lisa
Lisa - avatar
+ 2
Lisa thanks ☺️
30th Dec 2020, 3:29 PM
LordOfThunder [Inactive]
LordOfThunder [Inactive] - avatar
+ 2
I'm sorry but i still dont understand how to code the print function and to make it print in the final result
29th Jan 2021, 5:42 PM
Alvaro Bastia
Alvaro Bastia - avatar
+ 2
Alvaro Bastia The idea is to make print() a method of the contact object. The concept is this: function Obj(x) { this.x = x; print = function(){ console.log(this.x) } } var x = new Obj("Hi"); x.print()
29th Jan 2021, 5:52 PM
Lisa
Lisa - avatar
+ 2
LordOfThunder LordOfThunder Might you help me? I still haven't been able to solve
17th Feb 2021, 6:13 PM
Juan Barboza
Juan Barboza - avatar
+ 1
LordOfThunder Might you help me? I still haven't been able to solve
15th Feb 2021, 6:15 PM
Juan Barboza
Juan Barboza - avatar
18th Feb 2021, 6:14 AM
LordOfThunder [Inactive]
LordOfThunder [Inactive] - avatar
+ 1
Thanks so much Andre Ponce
21st May 2021, 1:37 PM
KEVIN GOMES
KEVIN GOMES - avatar
+ 1
I still cant do it right
19th Feb 2022, 2:18 PM
Nora Viera
Nora Viera - avatar
0
LordOfThunder I am Juan Barboza, please help me to solve this exercise, I still don't know the answer. I would appreciate
19th Feb 2021, 1:39 AM
Juan Barboza
Juan Barboza - avatar
0
Hi guys, I come with the solution function contact(name, number) { this.name = name; this.number = number; this.print = function (name,number) { return this.name +": "+ this.number } } var a = new contact("David", 12345); var b = new contact("Amy", 987654321) console.log(a.print()); console.log(b.print())
9th Mar 2021, 6:05 AM
Andre Ponce
Andre Ponce - avatar
0
i got it. function contact(name, number) { this.name = name; this.number = number; this.print = print function print (contact) { console.log(name + ": " + number) } } var a = new contact("David", 12345); var b = new contact("Amy", 987654321) a.print(); b.print();
2nd Aug 2022, 2:51 AM
Franconecta
Franconecta - avatar