I am doing a class exercise, where we have been asked to make a student class with three variables, one of them a literal object, my question is when accessing that literal object to be able to change the parameters, that is, how to change the StudentTest.mathematical.notes? how is it done? Because when doing this it tells me that mathematics is not defined.
I leave you what I have done
class Alumno {
constructor(nombre, apellido, notas) {
this._nombre = nombre || 'Sin nombre',
this._apellido = apellido || 'Sin apellido',
this._notas = notas || {
Matematicas: generaAleatorio(0, 10),
Lengua: generaAleatorio(0, 10),
Fisica: generaAleatorio(0, 10),
Ingles: generaAleatorio(0, 10),
Musica: generaAleatorio(0, 10)
}
}
}
function generaAleatorio(min, max) {
return Math.round(Math.random() * (max - min) + min);
}
var AlumnoPrueba = new Alumno();
AlumnoPrueba.nombre = "Paco";
AlumnoPrueba.apellido = "Martinez";
AlumnoPrueba.notas;
console.log(AlumnoPrueba);
You have inconsistencies in your code, the correct thing would be to access with
Because Javascript is case sensitive, and you forgot
_
which one you used when declaring the property.