+ 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();
3 Antworten
+ 5
make print function in contact function which will accept 2 values and print that.
Check the given example in lesson to understand.
+ 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.
+ 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();