0

JavaScript Method problem

Im having trouble solving the Contact Manager project at the end of module 5, here is my code. function contact(name, number) { this.name = name; this.number = number; function print (contact) { this.contact = contact; } } var a = new contact ("David", 12345); var b = new contact ("Amy", 987654321) a.print(); b.print(); it keeps saying print is not a function

16th Feb 2021, 3:30 PM
Margo DeVore
4 Respuestas
+ 2
You should review 34.1 "Adding Methods", it literally shows how to add a method to an Object Constructor. https://www.sololearn.com/learning/1154/
17th Feb 2021, 7:01 AM
ODLNT
ODLNT - avatar
+ 2
you must write like this: this.print=function (contact) { this.contact=conatct; }
17th Feb 2021, 1:20 PM
Mehran
Mehran - avatar
+ 1
Your code does not contain "contact" class. And "contact" constructor and "print" method should be inside of that class. And I have a feeling that you implemented "print" function wrong...
16th Feb 2021, 4:22 PM
#0009e7 [get]
#0009e7 [get] - avatar
+ 1
let print =()=>console.log(this)
16th Feb 2021, 8:28 PM
PS&Snow
PS&Snow - avatar