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
4 Antworten
+ 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/
+ 2
you must write like this:
this.print=function (contact) {
this.contact=conatct;
}
+ 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...
+ 1
let print =()=>console.log(this)