JSFiddle - React, Tailwind, and code Playground
JavaScript
class Estudante {
constructor(nome, matricula, sexo) {
this.nome = nome;
this.matricula = matricula;
this.sexo = sexo;
this.notas = [];
}
exibir() {
return 'Nome do estudante: ' + this.nome;
}
atribuirNota(n) {
this.notas.push(n);
}
lerNota(index) {
return this.notas[index - 1];
}
calcularMedia() {
var x = (this.notas.length);
var soma = 0;
for (i = 0; i < (x - 1); i++) {
soma += this.notas[i];
}
var media = soma / x;
return media;
}
}
class EstudanteMonitor extends Estudante {
exibir() {
return 'Nome do estudante monitor: ' + this.nome;
}
};
var e1 = new Estudante("João", 2, 3);
console.log(e1.exibir()); // "Nome do estudante: João
var em1 = new EstudanteMonitor("João", 2, 3);
console.log(em1.exibir()); // "Nome do estudante monitor: João"