+ 3

Add some code .how do it?pls explain me.

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();

10th Mar 2023, 12:59 AM
Kyaw Lin Aung
Kyaw Lin Aung - avatar
3 odpowiedzi
+ 5
make print function in contact function which will accept 2 values and print that. Check the given example in lesson to understand.
10th Mar 2023, 2:10 AM
A͢J
A͢J - avatar
+ 3
You should add a method to the constructor function like this: function Car(){ this.drive = function(){ console.log("driving") } } The drive function is a method just like print in your case and is called like this: let a = new Car() a.drive() Hope this example helped.
10th Mar 2023, 7:52 AM
Wayne Mwashuma
Wayne Mwashuma - avatar
+ 2
Kyaw Lin Aung 😊 //code project (contact number) intermediate //Javascript //you need to add the print method inside the // contact function (here it play the role of class). // it is going to work as I wrote it down. function contact(name, number) { this.name = name; this.number = number; // add this print function to your code😎😊😊👇 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();
10th Mar 2023, 6:40 PM
Yasin Rahnaward
Yasin Rahnaward - avatar