I'm stuck with the last part of this exercise, specifically the getFrecuencia method. The others are already passing all the tests well
I have tried to access the property with dot and bracket notation, but I cannot get the value of property 2 when receiving the string of property 1 as an argument
Exercice: actividades is an array of objects that has 2 properties, where I must obtain the value of property "b" from receiving property "a" as an argument
I would be grateful if someone could guide me with the logic or some clue of what I should do to solve the end of this exercise
function crearClaseMascota() {
class Mascota {
constructor(nombre, dueño, actividades) {
// El constructor de la clase Mascota recibe nombre (string), dueño (objeto), actividades (array de objetos)
// ej:
//[{actividad: 'salir a caminar', frecuencia: '1 vez al dia'}, {actividad: 'baño', frecuencia: '1 vez al mes'}]
// Inicializar las propiedades de la mascota.nombrelos valores recibidos como argumento
// Tu código aca:
this.nombre = nombre,
this.dueño = dueño,
this.actividades = actividades;
}
getNombre() {
// este método debe retornar el nombre de la mascota.
// Tu código aca:
// var savePetName = ((pet) => pet.nombre);
// var petName = this.Mascota.map(savePetName);
// return petName;
return this.nombre;
}
getDueño() {
// El método debe retornar nombre y apellido del dueño (concatenados).
// Tu código aca:
return this.dueño.nombre + ' ' + this.dueño.apellido;
}
addActividad(actividad, frecuencia) {
// El método recibe un string 'actividad' y otro string 'frecuencia' y debe agregarlo al arreglo de actividades de la mascota.nombre // No debe retornar nada.
// Tu código aca:
var newActivity = {
actividad: actividad,
frecuencia: frecuencia
};
this.actividades.push(newActivity);
}
getActividades() {
// El método debe retornar un arreglo con sólo las actividades de las mascotas.
// Ej:
// [{actividad: 'salir a caminar', frecuencia: '1 vez al dia'}, {actividad: 'baño', frecuencia: '1 vez al mes'}]
// mascotas.getActividades() debería devolver ['salir a caminar, 'baño']
// Tu código aca:
var saveActivity = ((pet) => pet.actividad);
var nameActivity = this.actividades.map(saveActivity);
return nameActivity;
}
getFrecuencia(actividad) {
// El metodo debe retornar la frecuencia de dicha actividad
// ej:
// [{actividad: 'salir a caminar', frecuencia: '1 vez al dia'}, {actividad: 'baño', frecuencia: '1 vez al mes'}]
// mascotas.getFrecuencia('baño') debería devolver '1 vez al mes'
// Tu código aca:
}
}
return Mascota;
}