0

I need help w a quiz

As you know there is a quiz for every end of lessons. In JS course, module 44 'Contact Manager App', I couldn't find how to do it. Here's the question and code; 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. And the code : 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()

15th Nov 2022, 8:59 AM
Enes
3 Antworten
+ 1
Please attempt the code or share the code then we can easily understand
15th Nov 2022, 9:42 AM
Sakshi [Offline 🙃]
Sakshi [Offline 🙃] - avatar
0
By doing a.print() youre callinga function inside a object that doesnt exist, all you need to do is add that function function contact(name, number) { this.name = name; this.number = number; // new print func this.print = function () { console.log(this.name, this.number) } // } You should look here to get better understanding of class, this and how declare functions inside
15th Nov 2022, 2:02 PM
Stanislav Stasyuk
Stanislav Stasyuk - avatar
0
The code is writing there 🙄 Sakshi Stanislav Stasyuk ı knoww, i did it like you said but it didn't work. Output is saying "unexpected token function"
17th Nov 2022, 4:32 AM
Enes