JavaScript - Crear un objeto para guardar contactos

 
Vista:

Crear un objeto para guardar contactos

Publicado por jose cardozo (1 intervención) el 14/01/2021 17:49:35
por favor necesito ayuda, soy nuevo
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.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
function contact(name, number) {
    this.name = name;
    this.number = number;
    this.print=() =>{
        console.log(this.name+":"+this.number);
 
    }
 
 
}
 
var a = new contact("David", 12345);
var b = new contact("Amy", 987654321);
a.print();
b.print();

Input
No Input
Your Output
David:12345
Amy:987654321
Expected Output
David: 12345

Amy: 987654321
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder
Imágen de perfil de joel
Val: 3.506
Oro
Ha mantenido su posición en JavaScript (en relación al último mes)
Gráfica de JavaScript

Crear un objeto para guardar contactos

Publicado por joel (895 intervenciones) el 14/01/2021 19:59:28
Segun entiendo te falta un espacio entre los dos puntos y el numero, no?

En vez de esto:
1
console.log(this.name+":"+this.number);
esto:
1
console.log(this.name+": "+this.number);

Coméntanos, ok?
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar