Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

326
Visualizações
Sintaxis de JavaScript III: ¿Por qué mi código no está definido en las calificaciones?

así que actualmente estoy trabajando en un proyecto en Code Academy, no estoy seguro de por qué se muestra indefinido. Aunque he visto el recorrido en video, el proyecto se llama Build a Library. Aquí está mi código completo:

Todavía estoy confundido con respecto a JavaScrip, así que tengan paciencia conmigo. ¡Gracias por los que responderán!

 class Media { constructor(title) { this._title = title; this._ratings = []; this._isCheckedOut = false; } get title() { return this._title; } get isCheckedOut() { return this._isCheckedOut; } get ratings() { return this._ratings; } set isCheckedOut(value) { this._isCheckedOut = value; } toggleCheckOutStatus() { this._isCheckedOut = !this._isCheckedOut; } getAverageRating() { let ratingsSum = this.ratings.reduce((accumulator, rating) => accumulator + rating); } addRating(value) { this.ratings.push(value); } } class Book extends Media { constructor(author, title, pages) { super(title); this._author = author; this._pages = pages; } get author() { return this._author; } get pages() { return this._pages; } } class Movie extends Media { constructor(director, title, runTime) { super(title); this._director = director; this._runTime = runTime; } get director() { return this._director; } get runTime() { return this._runTime; } } const historyOfEverything = new Book("Bill Bryson", "A Short History of Nearly Everything", 544); historyOfEverything.toggleCheckOutStatus(); console.log(historyOfEverything.isCheckedOut); historyOfEverything.addRating(4); historyOfEverything.addRating(5); historyOfEverything.addRating(5); console.log(historyOfEverything.getAverageRating()); const speed = new Movie("Jan de Bont", "Speed", 116); speed.toggleCheckOutStatus(); console.log(speed.isCheckedOut); speed.addRating(1); speed.addRating(1); speed.addRating(5); console.log(speed.getAverageRating());
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

debido a que no está devolviendo nada de la función getAverageRating, debe agregar: return ratingsSum/this.ratings.length si entendí lo que quiere hacer, por lo que toda la función será algo como esto:

 getAverageRating() { let ratingsSum = this.ratings.reduce( (accumulator, rating) => accumulator + rating ); return ratingsSum/this.ratings.length }
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda