¡Te damos la bienvenida a este reto!

1

¡Bienvenido al mundo de JavaScript!

Día 1

2

Variables, funciones y sintaxis básica

3

Tipos de datos

4

Playground - Retorna el tipo

5

Tipos de datos - pt 2

Día 2

6

Operadores

7

Hoisting y coerción

8

Playground - Calcula la propina

9

Alcance de las variables

Día 3

10

Condicionales

11

Playground - Calcula años bisiestos

12

Switch

13

Playground - Obten información de mascotas según su tipo

14

Ciclos

15

Playground - Dibuja un triangulo

Día 4

16

Arrays

17

Playground - Encuentra al michi mas famoso

18

Objetos

19

Playground - Obten el promedio de los estudiantes

Día 5 - Checkpoint

20

Playground - encuentra el palindromo más grande

Día 6

21

Reasignación y redeclaración

22

Modo estricto

Día 7

23

Debugging y manejo de errores

24

Programación funcional

Quiz: Día 7

Día 8

25

Closures

26

Playground - Crea una calculadora con closures

27

Higher order functions

28

Playground - Crea tu propio método map

Día 9

29

ECMAScript

30

TC39

Quiz: Día 9

Día 10 - Checkpoint

31

ES6

32

ES7

33

Playground - Task planner

Día 11

34

Asincronismo

35

Playground - Promesas

36

Manejando el asincronismo

37

Playground - Resuelve el callback hell usando promesas

38

Playground - Resuelve el callback hell usando async/await

Día 12

39

Arrays a profundidad

40

Métodos de arrays: Every, Find y findIndex

41

Playground - Válida el formulario

Día 13

42

Métodos de arrays: Includes, Join y concat

43

Playground - agrupa los productos

44

Métodos de arrays: Flat y FlatMap

45

Playground - Encuentra la ubicación del valor buscado

Día 14

46

Mutable functions

47

Playground - Modifica una lista de compras

48

Métodos de arrays: sort

49

Playground - Ordena los productos

Día 15 - Checkpoint

50

Playground - Sistema de reservaciones de un hotel

Día 16

51

Programación orientada a objetos en JavaScript

52

Objetos literales

53

Playground - Congela el objeto recursivamente

Día 17

54

Prototipos en JavaScript

55

Playground - Modifica el prototype de los arrays

56

Playground - Crea un auto usando clases

Día 18

57

Abstracción en JavaScript

58

Playground - Sistema de carrito de compras

59

Encapsulamiento en JavaScript

60

Playground - Encapsula datos de los usuarios

Día 19

61

Herencia en JavaScript

62

Playground - Jerarquía de animales

63

Polimorfismo en JavaScript

64

Playground - Sistema de pagos

Día 20 - Checkpoint

65

Playground - Agenda de vuelos

Día 21

66

Patrones de diseño

67

Sinlgeton y Factory pattern en JavaScript

68

Playground - Implementa singleton en un chat

Día 22

69

Adapter y Decorator pattern en JavaScript

70

Playground - Personaliza productos de una tienda

71

Builder y Protype pattern en JavaScript

72

Playground - Mejora el código usando builder pattern

Día 23

73

Facade y proxy pattern en JavaScript

74

Playground - Proxy en servicio de mensajería

75

Chain of responsability y Observer pattern en JavaScript

76

Playground - Implementación de Observador en Newsletter

Día 24 - Checkpoint

77

Playground - Crea un task manager con patrones de diseño

Día 25

78

Estructuras de datos en JavaScript

79

Playground - Crea tu propia implementación de un array

80

Hash tables en JavaScript

81

Playground - Implementación de una HashTable para Contactos

Día 26

82

Set en JavaScript

83

Playground - Remueve duplicados de una lista

84

Maps en JavaScript

85

Playground - Crea un organizador de tareas

Día 27

86

Singly Linked List en JavaScript

87

Playground - Agrega métodos a la singly linked list

88

Playground - Implementación de una singly linked list

Día 28

89

Stacks en JavaScript

90

Playground - Crea un stack para una playlist

Día 29

91

Queues en JavaScript

92

Playground - Crea una cola de emails

Día 30

93

¡Lo lograste!

Live Class

94

30 días de JS con Juan DC

95

30 días de JS con Nicobytes

96

30 días de JS con GNDX

97

30 días de JS con LeoCode

98

30 días de JS con Teffcode

99

Sesión: Cierre de los 30 días de JavaScript

No tienes acceso a esta clase

¡Continúa aprendiendo! Únete y comienza a potenciar tu carrera

Playground - Agenda de vuelos

65/99

Aportes 30

Preguntas 1

Ordenar por:

¿Quieres ver más aportes, preguntas y respuestas de la comunidad?

Excelente Reto, hay que estar bien atento a las indicaciones de la guia y en especial tener un poco de logica para interpretar, ya que implicitamente debemos descontar el capacity una vez que se venda algun ticket del Flight.

Les dejo mi solucion. Saludos

Para Reservation.js

export class Reservation {
  constructor(flight, passenger) {
    this.flight = flight;
    this.passenger = passenger;
  }

  reservationDetails() {
    const { origin, destination, date } = this.flight;
    const { name, lastName } = this.passenger;
    return {
      origin,
      destination,
      date,
      reservedBy: `${name} ${lastName}`,
    };
  }
}

Para Passenger.js

export class Passenger {
  constructor(name, lastName, age) {
    this.name = name;
    this.lastName = lastName;
    this.age = age;
    this.flights = [];
  }

  addFlight(flight) {
    const { origin, destination, date, price } = flight;
    this.flights.push({
      origin,
      destination,
      date,
      price,
    });
  }
}

Para Flight.js

import { Reservation } from './Reservation';

export class Flight {
  constructor(origin, destination, date, capacity, price) {
    this.origin = origin;
    this.destination = destination;
    this.date = date;
    this.capacity = capacity;
    this.price = price;
    this.passengers = [];
  }

  addFlightToPassenger(passenger) {
    passenger.addFlight(this);
  }

  sellTicket(passenger) {
    if (this.capacity > 0) {
      this.passengers.push({
        fullName: `${passenger.name} ${passenger.lastName}`,
        age: passenger.age,
      });
      this.capacity -= 1;
      this.addFlightToPassenger(passenger);
      return new Reservation(this, passenger);
    }
  }
}

Para PremiumFlight.js

import { Flight } from './Flight';
import { Reservation } from './Reservation';

export class PremiumFlight extends Flight {
  constructor(origin, destination, date, capacity, price, specialService) {
    super(origin, destination, date, capacity, price);
    this.specialService = specialService;
  }

  // Override to apply logic
  addFlightToPassenger(passenger) {
    this.price += this.specialService;
    passenger.addFlight(this);
  }
}

Y para EconomicFlight.js

import { Flight } from './Flight';
import { Reservation } from './Reservation';

export class EconomicFlight extends Flight {
  // Override to apply logic
  addFlightToPassenger(passenger) {
    if (passenger.age < 18 || passenger.age > 65) {
      this.price *= 0.8;
    }
    passenger.addFlight(this);
  }
}

Escudo anti-spoilers

Muy entretenido el reto, y se vuelve muy fácil cuando se tiene los conocimientos de los cursos recomendados en el post del reto #PlatziChallenge: 30 días de JavaScript

A continuación comparto mi solución 😎

EconomicFlight.js

En este módulo es importante considerar que si hacemos algún cambio directo el precio como lo hizo @luisgv94, las próximas iteraciones, el precio del vuelo no será el correcto, es por ello que agregué una variable auxiliar que me permite recuperar el precio anterior.

import { Flight } from "./Flight";
import { Reservation } from "./Reservation";

export class EconomicFlight extends Flight {
  constructor(origin, destination, date, capacity, price) {
    super(origin, destination, date, capacity, price);
  }
  sellTicket(passenger) {
    // Tu código aquí 👇
    if (this.lastPrice != undefined) {
      this.price = this.lastPrice
    }
    if (passenger.age < 18 || passenger.age > 65) {
      this.lastPrice = this.price
      this.price = this.price * 0.8;
    }
    return super.sellTicket(passenger);
  }
}

Flight.js

🤔 Para este módulo es importante tomar en cuenta que cada vez que se venda un ticket, la capacidad del vuelo debe decrementar

import { Reservation } from "./Reservation";

export class Flight {
  constructor(origin, destination, date, capacity, price) {
    // Tu código aquí 👈
    this.origin = origin;
    this.destination = destination;
    this.date = date;
    this.capacity = capacity;
    this.price = price;
    this.passengers = [];
  }

  sellTicket(passenger) {
    if (this.capacity > 0) {
      this.passengers.push({
        fullName: `${passenger.name} ${passenger.lastName}`,
        age: passenger.age,
      });
      passenger.addFlight(this);
      let reservation = new Reservation(this, passenger);
      this.capacity--;
      return reservation;
    }
    // Tu código aquí 👈
  }
}

Passenger.js

Nada que comentar en este módulo, la explicación muy clara en este inciso.

export class Passenger {
  // Tu código aquí 👈
  constructor(name, lastName, age) {
    this.name = name;
    this.lastName = lastName;
    this.age = age;
    this.flights = [];
  }
  addFlight(flight) {
    this.flights.push({
      origin: flight.origin,
      destination: flight.destination,
      date: flight.date,
      price: flight.price,
    });
  }
}

PremiumFlight.js

Aquí no sé si hice un poco de trampa, pero al no ser clara las instrucciones también es posible agregar directamente el precio de specialService a la variable this.price y así nos evitamos sobreescribir el método addFlightToPassenger

import { Flight } from "./Flight";
import { Reservation } from "./Reservation";

export class PremiumFlight extends Flight {
  constructor(origin, destination, date, capacity, price, specialService) {
    // Tu código aquí 👈
    super(origin, destination, date, capacity, price)
    this.price = price + specialService
  }
}

Reservation.js

Aquí solamente considerar bien los nombres de variables como reservedBy fullName, etc.

export class Reservation {
  constructor(flight, passenger) {
    // Tu código aquí 👈
    this.flight = flight;
    this.passenger = passenger;
  }

  reservationDetails() {
    // Tu código aquí 👈
    return {
      origin: this.flight.origin,
      destination: this.flight.destination,
      date: this.flight.date,
      reservedBy: `${this.passenger.name} ${this.passenger.lastName}`,
    };
  }
}

NUNCA PARES DE APRENDER!

Oigame, Oigame, Oigame, un fuerte aplauso para todos los que hemos llegado aquí, y hemos luchado contra nosotros mismos para lograr estos lindos desafíos que nos ha dado Platzi.
Quiero recalcar, que si capacidad es igual a 0 no se debe retornar nada, es decir, undefined… ahora sí, dejo mi código… espero que les sirva, como a mi me ha servido algunos de ustedes… 😃

export class Flight {
  constructor(origin, destination, date, capacity, price) {
    this.origin = origin;
    this.date = date;
    this.destination = destination;
    this.capacity = capacity;
    this.price = price;
    this.passengers = [];

  }
  sellTicket(passenger) {
    // Tu código aquí 👇
    if (this.capacity > 0) {
      let res = {
        origin: this.origin,
        destination: this.destination,
        date: this.date,
        price: this.price
      }

      this.capacity--;
      let reservation = new Reservation(res, passenger);

      this.passengers.push(reservation.full);
      passenger.flights.push(res) //agregar el vuelo

      return reservation
    } 
  }
}
export class EconomicFlight extends Flight {

  constructor(origin, destination, date, capacity, price) {
    super(origin, destination, date, capacity, price);

  }

  sellTicket(passenger) {
    // Tu código aquí 👇

    if (passenger.age < 18 || passenger.age > 65) {
      this.price = this.price - (this.price * 0.2);

      return super.sellTicket(passenger);
    } else {
      return super.sellTicket(passenger);
    }

  }
}
export class Passenger {
    // Tu código aquí 👈
    constructor(name,lastName, age) {
        this.name = name;            
        this.age = age;
        this.full = {fullName:`${name} ${lastName}`,age:this.age}
        this.flights = [];
    }
  }
export class PremiumFlight extends Flight {
  constructor(origin, destination, date, capacity, price, specialService) {
    // Tu código aquí 👈
    super(origin, destination, date, capacity, price + specialService);
  
  }


}
export class Reservation {
  constructor(flight, passenger) {
    // Tu código aquí 👈
   this.flight = flight;
   this.passenger = passenger;
   this.full = passenger.full;
    this.age = passenger.age;
    this.origin = flight.origin;
    this.destination = flight.destination;
    this.date = flight.date;
    this.reservedBy = passenger.full.fullName
  }

  reservationDetails() {
    // Tu código aquí 👈

    return {
      origin: this.origin,
      destination: this.destination,
      date: this.date,
      reservedBy: this.reservedBy
    }
  }
} 

Aporto mi respuesta!
.
.
.
.
.
.
.
.
.

Reservation.js

export class Reservation {
  constructor(flight, passenger) {
    this.flight = flight
    this.passenger = passenger
  }

  reservationDetails() {
    return {'origin':this.flight.origin,'destination':this.flight.destination,'date':this.flight.date,'reservedBy':this.passenger.name+' '+this.passenger.lastName}
  }
} 

Passenger.js

export class Passenger {
  constructor(name, lastName, age) {
    this.name = name
    this.lastName = lastName
    this.age = age
    this.flights = []
  }

  addFlight(origin, destination, date, price) {
    this.flights.push(
      {
        'origin': origin,
        'destination': destination,
        'date': date,
        'price': price
      })
  }
}

Flight.js

import { Reservation } from "./Reservation";

export class Flight {
  constructor(origin, destination, date, capacity, price) {
    this.origin = origin
    this.destination = destination
    this.date = date
    this.capacity = capacity
    this.price = price
    this.passengers = []
  }

  sellTicket(passenger,price=this.price) {
    if (this.capacity > 0) {
      passenger.addFlight(this.origin, this.destination, this.date, price)
      this.passengers.push(
        {
          'age':passenger.age,
          'fullName': passenger.name + " " + passenger.lastName,
        }
      )
      this.capacity--

      //Para que no se modifique el precio original del vuelo al aplicar descuentos
      let temp = this
      temp.price = price
      return new Reservation(temp,passenger)
    }
  }
}

EconomicFlight.js

import { Flight } from "./Flight";

export class EconomicFlight extends Flight {
  constructor(origin, destination, date, capacity, price) {
    super(origin, destination, date, capacity, price)
    this.discountPrice = price*0.8
  }
  
  sellTicket(passenger) {
    if (passenger.age > 65 || passenger.age < 18) return super.sellTicket(passenger, this.discountPrice)
    else return super.sellTicket(passenger,this.price)
  }
}

PremiumFlight.js

import { Flight } from "./Flight";

export class PremiumFlight extends Flight {
  constructor(origin, destination, date, capacity, price, specialService) {
    super(origin, destination, date, capacity, price)
    this.price += specialService
  }

  sellTicket(passenger) {
    return super.sellTicket(passenger)
  }
}

Debido a que aun no se puede editar los comentarios hehe (ya creo que es hora) voy a subir una actualizacion de mi solucion propuesta con creditos y agradecimientos especiales a @DavidOchoa. Pues si es necesario no modificar la propiedad price del EconomicFlight cada vez que se venda algun ticket. Por ello en el metodo que propuse addFlightToPassenger() estoy haciendo una copia del objeto this que representa al Flight y asi evito modicar el precio cuando se cree la reservacion una vez vendido el ticket de avion.
.
.
.
.

Para Flight.js

import { Reservation } from './Reservation';

export class Flight {
  constructor(origin, destination, date, capacity, price) {
    this.origin = origin;
    this.destination = destination;
    this.date = date;
    this.capacity = capacity;
    this.price = price;
    this.passengers = [];
  }

  addFlightToPassenger(passenger) {
    passenger.addFlight(this);
    return this;
  }

  sellTicket(passenger) {
    if (this.capacity > 0) {
      this.passengers.push({
        fullName: `${passenger.name} ${passenger.lastName}`,
        age: passenger.age,
      });
      this.capacity -= 1;
      const cloneFlight = this.addFlightToPassenger(passenger);
      return new Reservation(cloneFlight, passenger);
    }
  }
}

Para EconomicFlight.js

import { Flight } from './Flight';
import { Reservation } from './Reservation';

export class EconomicFlight extends Flight {
  // Override to apply logic
  addFlightToPassenger(passenger) {
    const cloneFlight = { ...this };
    if (passenger.age < 18 || passenger.age > 65) {
      cloneFlight.price *= 0.8;
    }
    passenger.addFlight(cloneFlight);
    return cloneFlight;
  }
}

Para PremiumFlight.js (Gran hack del amigo David)

import { Flight } from './Fli';
import { Reservation } from './Reservation';

export class PremiumFlight extends Flight {
  constructor(origin, destination, date, capacity, price, specialService) {
    super(origin, destination, date, capacity, price);
    this.price += specialService;
  }
}

Passenger.js

export class Passenger {
  constructor(name, lastName, age) {
    this.name = name;
    this.lastName = lastName;
    this.age = age;
    this.flights = [];
  }

  addFlight(flight) {
    const { origin, destination, date, price } = flight;
    this.flights.push({
      origin,
      destination,
      date,
      price,
    });
  }
}

Reservation

export class Reservation {
  constructor(flight, passenger) {
    this.flight = flight;
    this.passenger = passenger;
  }

  reservationDetails() {
    const { origin, destination, date } = this.flight;
    const { name, lastName } = this.passenger;
    return {
      origin,
      destination,
      date,
      reservedBy: `${name} ${lastName}`,
    };
  }
}

Buenísimo el ejercicio, la verdad excelente para practicar. Lamentablemente la redacción de estos retos son un dolor de cabeza…

Aqui mi solución:

Muy interesante el reto, me pasó que solo hasta ver las pruebas unitarias caí en cuenta de disminuir la cantidad de asientos disponibles del vuelo.
Otro detalle es evitar modificar el precio original del vuelo por aplicar un descuento o un aumento de precio por vuelo premium.

EconomicFlight.js

import { Flight } from "./Flight";
import { Reservation } from "./Reservation";

export class EconomicFlight extends Flight {
  constructor(origin, destination, date, capacity, price) {
    super(origin, destination, date, capacity, price);
  }

  sellTicket(passenger) {
    let specialPrice = '';
    if (passenger.age < 18 || passenger.age > 65) {
      specialPrice = this.price * 0.8;
    }
    return super.sellTicket(passenger, specialPrice);
  }
}

Flight.js

import { Reservation } from "./Reservation";

export class Flight {
  constructor(origin, destination, date, capacity, price) {
    this.origin = origin;
    this.destination = destination;
    this.date = date;
    this.capacity = capacity;
    this.price = price;
    this.passengers = [];
  }

  sellTicket(passenger, specialPrice) {
    console.log('sellTicket');
    console.log('passenger: ', passenger);

    if (this.capacity > 0) {
      this.passengers.push({
        fullName: `${passenger.name} ${passenger.lastName}`,
        age: passenger.age
      });

      this.capacity -= 1;

      const flightCopy = {
        origin: this.origin,
        destination: this.destination,
        date: this.date,
        price: specialPrice? specialPrice: this.price
      }

      passenger.flights.push(flightCopy);

      return new Reservation(flightCopy, passenger);
    }
  }
}

Passenger.js

export class Passenger {
    constructor(name, lastName, age) {
      this.name = name;
      this.lastName = lastName;
      this.age = age;
      this.flights = [];
    }
  }

PremiumFlight.js

import { Flight } from "./Flight";
import { Reservation } from "./Reservation";

export class PremiumFlight extends Flight {
  constructor(origin, destination, date, capacity, price, specialService) {
    super(origin, destination, date, capacity, price);
    this.specialService = specialService;
  }

  sellTicket(passenger) {
    let specialPrice = this.price + this.specialService;
    return super.sellTicket(passenger, specialPrice);
  }
}

Reservation.js

export class Reservation {
  constructor(flight, passenger) {
    this.flight = flight;
    this.passenger = passenger;
  }

  reservationDetails() {
    return {
      origin: this.flight.origin,
      destination: this.flight.destination,
      date: this.flight.date,
      reservedBy: `${this.passenger.name} ${this.passenger.lastName}`
    }
  }
} 

Desafio completado:

Mi solución 💚
Cuidado con la lógica de disminuir la capacidad y también vean los ejemplos para ver que se espera que se agregue del pasajero en el vuelo (ya que yo cometí el error de pasar toda la referencia jaja 😅)

Flight.js

import { Reservation } from "./Reservation";

export class Flight {
  constructor(origin, destination, date, capacity, price) {
    this.origin = origin
    this.destination = destination
    this.date = date
    this.capacity = capacity
    this.price = price
    this.passengers = []
  }

  sellTicket(passenger) {
    if (this.capacity <= 0)
      return 

    this.passengers.push({
      fullName: `${passenger.name} ${passenger.lastName}`,
      age: passenger.age
    })
    passenger.flights.push({
      origin: this.origin,
      destination: this.destination,
      date: this.date,
      price: this.price
    })

    this.capacity--;

    return new Reservation(this, passenger)
  }
}

Passenger.js

export class Passenger {
  constructor(name, lastName, age) {
    this.name = name 
    this.lastName = lastName
    this.age = age
    this.flights = []
  }
}

Reservation.js

export class Reservation {
  constructor(flight, passenger) {
    this.flight = flight
    this.passenger = passenger
  }

  reservationDetails() {
    return {
      origin: this.flight.origin,
      destination: this.flight.destination,
      date: this.flight.date,
      reservedBy: `${this.passenger.name} ${this.passenger.lastName}`
    }
  }
} 

PremiumFlight.js

import { Flight } from "./Flight";

export class PremiumFlight extends Flight {
  constructor(origin, destination, date, capacity, price, specialService) {
    super(origin, destination, date, capacity, price)
    this.specialService = specialService
  }

  sellTicket(passenger) {
    this.price += this.specialService;
    return super.sellTicket(passenger)
  }
}

EconomicFlight.js

import { Flight } from "./Flight";

export class EconomicFlight extends Flight {
  sellTicket(passenger) {
    if (passenger.age < 18 || passenger.age > 65) 
      this.price -= (this.price * 0.20)

    return super.sellTicket(passenger)
  }
}

Flight

constructor(origin, destination, date, capacity, price) {
    this.origin = origin;
    this.destination = destination;
    this.date = date;
    this.capacity = capacity;
    this.price = price;
    this.passengers = [];
  }

  sellTicket(passenger) {
    if (this.capacity > 0) {
      this.passengers.push(passenger);
      passenger.flights.push({
        origin: this.origin,
        destination: this.destination,
        date: this.date,
        price: this.price
      });
      this.capacity--;
      return new Reservation(this, passenger);
    } else {
      console.log("el vuelo esta lleno");
    }
  }

Passenger

export class Passenger {
  constructor(name, lastName, age) {
    this.name = name;
    this.lastName = lastName;
    this.age = age;
    this.flights = [];
  }
}

Reservation

export class Reservation {
  constructor(flight, passenger) {
    this.flight = flight;
    this.passenger = passenger;
  }

  reservationDetails() {
    return {
      origin: this.flight.origin,
      destination: this.flight.destination,
      date: this.flight.date,
      reservedBy: `${this.passenger.name} ${this.passenger.lastName}`
    };
  }
}  

PremiumFlight

export class PremiumFlight extends Flight {
  constructor(origin, destination, date, capacity, price, specialService) {
    super(origin, destination, date, capacity, price);
    this.specialService = specialService;
  }

  sellTicket(passenger) {
    const reservation = super.sellTicket(passenger);
    if (reservation) {
      reservation.flight.price += this.specialService;
    }
    return reservation;
  }
}

EconomicFlight

export class EconomicFlight extends Flight {
  sellTicket(passenger) {
    if (passenger.age < 18 || passenger.age > 65) {
      this.price *= 0.8; // Apply 20% discount
    }
    return super.sellTicket(passenger);
  }
}

Hola

👏
👏
👏
👏
👏
👏
👏
👏
👏
👏

Flight.js

import { Reservation } from "./Reservation";

export class Flight {
  constructor(origin, destination, date, capacity, price) {
    this.origin = origin;
    this.destination = destination;
    this.date = date;
    this._capacity = capacity;
    this.price = price;
    this.passengers = [];
  }

  get capacity() {
    return this._capacity - this.passengers.length;
  }

  set capacity(capacity) {
    this._capacity = capacity;
  }

  sellTicket(passenger) {
    if (this.capacity > 0) {
      passenger.flights.push(
        {
          origin : this.origin,
          destination : this.destination,
          date : this.date,
          price : this.price
        }
      );
      
      this.passengers.push({
        fullName : passenger.name + ' ' + passenger.lastName,
        age: passenger.age
      });
      
      return new Reservation(this, passenger);
    }
  }
}

Passenger.js

export class Passenger {
  constructor(name, lastName, age) {
    this.name = name;
    this.lastName = lastName;
    this.age = age;
    this.flights = [];
  }
}

PremiumFlight.js

import { Flight } from "./Flight";
import { Reservation } from "./Reservation";

export class PremiumFlight extends Flight {
  constructor(origin, destination, date, capacity, price, specialService) {
    super(origin, destination, date, capacity, price + specialService);
    this.specialService = specialService;
  }

  sellTicket(passenger) {
    return super.sellTicket(passenger);
  }
}

Reservation.js

export class Reservation {
  constructor(flight, passenger) {
    this.flight = flight;
    this.passenger = passenger;
  }

  reservationDetails() {
    return {
      origin: this.flight.origin,
      destination: this.flight.destination,
      date: this.flight.date,
      reservedBy: this.passenger.name + ' ' + this.passenger.lastName,
    };
  }
}

EconomicFlight.js

import { Flight } from "./Flight";
import { Reservation } from "./Reservation";

export class EconomicFlight extends Flight {
  constructor(origin, destination, date, capacity, price) {
    super(origin, destination, date, capacity, price);
  }

  sellTicket(passenger) {
    let priceNew = this.price;
    if (passenger.age < 18 || passenger.age > 65) {
      priceNew -= this.price * 0.2;
    }

    if (this.capacity > 0) {
      passenger.flights.push({
        origin: this.origin,
        destination: this.destination,
        date: this.date,
        price: priceNew,
      });

      this.passengers.push({
        fullName: passenger.name + " " + passenger.lastName,
        age: passenger.age,
      });

      return new Reservation({
        origin: this.origin,
        destination: this.destination,
        date: this.date,
        price: priceNew,
      }, passenger);
    }
  }
}


.
.
.
.
.

EconomicFlight.js:

import { Flight } from "./Flight";
import { Reservation } from "./Reservation";

export class EconomicFlight extends Flight {
  sellTicket(passenger) {
    if (passenger.age < 18 || passenger.age > 65) {
      this.price *= 0.80
    }
    return super.sellTicket(passenger);
  }
}

Flight.js:

import { Reservation } from "./Reservation";

export class Flight {
  constructor(origin, destination, date, capacity, price) {
    this.origin = origin;
    this.destination = destination;
    this.date = date;
    this.capacity = capacity;
    this.price = price;
    this.passengers = [];
  }

  sellTicket(passenger) {
    if (this.capacity > 0) {
      let reservation = new Reservation(this, passenger);
      this.passengers.push({
        fullName: passenger.fullName,
        age: passenger.age
      });
      passenger.addFlight(this);
      this.capacity--;
      return reservation;
    }
  }
}

Passenger.js:

export class Passenger {
  constructor(name, lastName, age) {
    this.fullName = name + " " + lastName;
    this.age = age;
    this.flights = [];
  }

  addFlight(flight) {
    this.flights.push(
      {
        'origin': flight.origin,
        'destination': flight.destination,
        'date': flight.date,
        'price': flight.price
      })
  }
}

PremiumFlight.js:

import { Flight } from "./Flight";
import { Reservation } from "./Reservation";

export class PremiumFlight extends Flight {
  constructor(origin, destination, date, capacity, price, specialService) {
    super(origin, destination, date, capacity, price);
    this.price += specialService;
  }

  sellTicket(passenger) {
    return super.sellTicket(passenger);
  }
}

Reservation.js:

export class Reservation {
  constructor(flight, passenger) {
    this.flight = flight;
    this.passenger = passenger;
  }

  reservationDetails() {
    return {
      "origin": this.flight.origin,
      "destination": this.flight.destination,
      "date": this.flight.date,
      "reservedBy": this.passenger.fullName
    }
  }

🛡️🛡️Escudo anti-spoilers🛡️🛡️

Mi solución al reto:

EconomicFlight.js

import { Flight } from './Flight';

export class EconomicFlight extends Flight {
  // Override to apply logic
  addFlightToPassenger(passenger) {
    if (passenger.age < 18 || passenger.age > 65) {
      this.price *= 0.8;
    }
    passenger.addFlight(this);
  }
}

Flight.js

import { Reservation } from './Reservation';

export class Flight {
  constructor(origin, destination, date, capacity, price) {
    this.origin = origin;
    this.destination = destination;
    this.date = date;
    this.capacity = capacity;
    this.price = price;
    this.passengers = [];
  }

  addFlightToPassenger(passenger) {
    passenger.addFlight(this);
  }

  sellTicket(passenger) {
    if (this.capacity > 0) {
      this.passengers.push({
        fullName: `${passenger.name} ${passenger.lastName}`,
        age: passenger.age,
      });
      this.capacity -= 1;
      this.addFlightToPassenger(passenger);
      return new Reservation(this, passenger);
    }
  }
}

Passenger.js

export class Passenger {
  constructor(name, lastName, age) {
    this.name = name;
    this.lastName = lastName;
    this.age = age;
    this.flights = [];
  }

  addFlight(flight) {
    const { origin, destination, date, price } = flight;
    this.flights.push({
      origin,
      destination,
      date,
      price,
    });
  }
}

PremiumFlight.js

import { Flight } from './Flight';

export class PremiumFlight extends Flight {
  constructor(origin, destination, date, capacity, price, specialService) {
    super(origin, destination, date, capacity, price);
    this.specialService = specialService;
  }

  // Override to apply logic
  addFlightToPassenger(passenger) {
    this.price += this.specialService;
    passenger.addFlight(this);
  }
}

Reservation.js

export class Reservation {
  constructor(flight, passenger) {
    this.flight = flight;
    this.passenger = passenger;
  }

  reservationDetails() {
    const { origin, destination, date } = this.flight;
    const { name, lastName } = this.passenger;
    return {
      origin,
      destination,
      date,
      reservedBy: `${name} ${lastName}`,
    };
  }
}
``

Solucion

Reservation.js

export class Reservation {
  constructor(flight, passenger) {
    // Tu código aquí 👈
    this.flight = flight;
    this.passenger = passenger;
  }

  reservationDetails() {
    // Tu código aquí 👈
    return {
      flightDetails: this.flight,
      passenger: this.passenger,
    };
  }
}

Flight.js

import { Reservation } from "./Reservation.mjs";

export class Flight {
  constructor(origin, destination, date, capacity, price) {
    // Tu código aquí 👈
    this.origin = origin;
    this.destination = destination;
    this.date = date;
    this.capacity = capacity;
    this.price = price;
    this.passengers = [];
  }

  sellTicket(passenger) {
    // Tu código aquí 👈
    if (this.capacity > 0) {
      // Add passenger and reduce capacity by each indivudial
      this.passengers.push({
        fullName: `${passenger.name} ${passenger.lastName}`,
        age: passenger.age,
      });
      this.capacity -= 1;

      // Add flight to passenger's data
      passenger.flights.push({
        origin: this.origin,
        destination: this.destination,
        date: this.date,
        price: this.price,
      });

      return new Reservation(this, passenger);
    }
  }
}

Passenger.js

export class Passenger {
  // Tu código aquí 👈
  constructor(name, lastName, age) {
    this.name = name;
    this.lastName = lastName;
    this.age = age;
    this.flights = [];
  }
}

PremiumFlight.js

import { Flight } from "./Flight.mjs";
import { Reservation } from "./Reservation.mjs";

export class PremiumFlight extends Flight {
  constructor(origin, destination, date, capacity, price) {
    super(origin, destination, date, capacity, price);
    this.passengers = [];
    this.specialService = 1.2;
  }

  sellTicket(passenger) {
    if (this.capacity > 0) {
      // Add passenger and reduce capacity by each indivudial
      this.passengers.push(passenger);
      this.capacity -= 1;

      // Add flight to passenger's data
      passenger.flights.push({
        origin: this.origin,
        destination: this.destination,
        date: this.date,
        price: (this.price *= this.specialService),
      });

      return new Reservation(this, passenger);
    }
  }
}

EconomicFlight.js

import { Flight } from "./Flight.mjs";
import { Reservation } from "./Reservation.mjs";

export class EconomicFlight extends Flight {
  constructor(origin, destination, date, capacity, price) {
    super(origin, destination, date, capacity, price);
    this.passengers = [];
  }

  sellTicket(passenger) {
    if (this.capacity > 0) {
      // Check passenger's age for discount
      const hasDiscountPrice = passenger.age < 18 || passenger.age > 65;

      // Add passenger and reduce capacity by each indivudial
      this.passengers.push(passenger);
      this.capacity -= 1;

      // Add flight to passenger's data
      passenger.flights.push({
        origin: this.origin,
        destination: this.destination,
        date: this.date,
        price: hasDiscountPrice ? (this.price *= 0.8) : this.price,
      });

      return new Reservation(this, passenger);
    }
  }
}

Aquí mi solución:
.
.
.
.
.
.
.
.
.
.
.
.

Flight.js

export class Flight {
  constructor(origin, destination, date, capacity, price) {
    this.origin = origin;
    this.destination = destination;
    this.date = date;
    this.capacity = capacity;
    this.price = price;
    this.passengers = [];
  }

  sellTicket(passenger) {
    if (this.capacity > 0) {
      this.passengers.push({
        fullName: passenger.name + " " + passenger.lastName,
        age: passenger.age
      });
      this.capacity--;
      passenger.addFlight({
        origin: this.origin,
        destination: this.destination,
        date: this.date,
        price: this.price
      })
      return new Reservation(this, passenger)
    }
  }
}

Passenger.js

export class Passenger {
  constructor(name, lastName, age) {
    this.name = name;
    this.lastName = lastName;
    this.age = age;
    this.flights = [];
  }

  addFlight(flight) {
    this.flights.push(flight);
  }
}

EconomicFlight.js

export class EconomicFlight extends Flight {
  sellTicket(passenger) {
    if (passenger.age < 18 || passenger.age > 65) {
      this.price *= 0.80
    }
    return super.sellTicket(passenger);
  }
}

PremiumFlight.js

export class PremiumFlight extends Flight {
  constructor(origin, destination, date, capacity, price, specialService) {
    super(origin, destination, date, capacity, price)
    this.specialService = specialService
  }

  sellTicket(passenger) {
    this.price += this.specialService;
    return super.sellTicket(passenger);
  }
}

Reservation.js

export class Reservation {
  constructor(flight, passenger) {
    this.flight = flight
    this.passenger = passenger
  }

  reservationDetails() {
    return {
      origin: this.flight.origin,
      destination: this.flight.destination,
      date: this.flight.date,
      reservedBy: this.passenger.name + " " + this.passenger.lastName
    }

  }
}

Solución.
Reservation.js

export class Reservation {
  constructor(flight, passenger) {
    // Tu código aquí 👈
    this.flight = flight;
    this.passenger = passenger;
  }

  reservationDetails() {
    // Tu código aquí 👈
    return {
      origin: this.flight.origin,
      destination: this.flight.destination,
      date: this.flight.date,
      reservedBy: this.passenger.getFullName()
    }
  }
} 

Passenger.js

export class Passenger {
  // Tu código aquí 👈
  constructor(name, lastName, age) {
    this.name = name;
    this.lastName = lastName;
    this.age = age;
    this.flights = [];
  }

  getFullName() {
    return this.name + ' ' + this.lastName;
  }

  addFlight(flight) {
    this.flights.push(flight);
  }
}

Flight.js

import { Reservation } from "./Reservation";

export class Flight {
  constructor(origin, destination, date, capacity, price) {
    // Tu código aquí 👈
    this.origin = origin;
    this.destination = destination;
    this.date = date;
    this.capacity = capacity;
    this.price = price;
    this.passengers = [];
  }

  sellTicket(passenger) {
    // Tu código aquí 👈
    if (this.capacity > 0) {      
      this.passengers.push({
        fullName: passenger.getFullName(),
        age: passenger.age
      });
      this.capacity--;

      const flight = {
        origin: this.origin,
        destination: this.destination,
        date: this.date,
        price: this.price
      };
      passenger.addFlight(flight);

      return new Reservation(flight, passenger);
    } 
  }
}

EconomicFlight.js

import { Flight } from "./Flight";
import { Reservation } from "./Reservation";

export class EconomicFlight extends Flight {
  constructor(origin, destination, date, capacity, price) {
    super(origin, destination, date, capacity, price);
  }

  sellTicket(passenger) {
    // Tu código aquí 👇
    if (passenger.age < 18 || passenger.age > 65) {
      this.price -= (this.price * 0.20);
    }
    return super.sellTicket(passenger);
  }
}

PremiumFlight.js

import { Flight } from "./Flight";
import { Reservation } from "./Reservation";

export class PremiumFlight extends Flight {
  constructor(origin, destination, date, capacity, price, specialService) {
    // Tu código aquí 👈
    super(origin, destination, date, capacity, price);
    this.specialService = specialService;
  }

  sellTicket(passenger) {
    // Tu código aquí 👈
    this.price += this.specialService;
    return super.sellTicket(passenger);
  }
}

my expectacular code

Flight

import { Reservation } from "./Reservation.js";

export class Flight {
  constructor(origin, destination, date, capacity, price) {
    this.origin = origin
    this.destination = destination
    this.date = date
    this.capacity = capacity
    this.price = price
    this.passengers = []
  }

  sellTicket(passenger) {
    if (this.capacity > 0) {
      this.passengers.push({
        fullName: `${passenger.name} ${passenger.lastName}`,
        age: passenger.age,
      });
      this.capacity--
      passenger.addFlight(this)
      return new Reservation(this, passenger);
    }
  }
}

Passenger

export class Passenger {
  constructor(name, lastName, age) {
    this.name = name
    this.lastName = lastName
    this.age = age
    this.flights = []
  }
  addFlight(flight) {
    const { origin, destination, date, price } = flight;
    this.flights.push({
      origin,
      destination,
      date,
      price,
    });
  }
}

Reservation

export class Reservation {
  constructor(flight, passenger) {
    this.flight = flight
    this.passenger = passenger
  }

  reservationDetails() {
    return { origin: this.flight.origin, destination: this.flight.destination, date: this.flight.date, reservedBy: this.passenger.name + ' ' + this.passenger.lastName }
  }
} 

EconomicFlight

import { Flight } from “./Flight.js”;
import { Reservation } from “./Reservation.js”;

export class EconomicFlight extends Flight {
constructor(origin, destination, date, capacity, price) {
super(origin, destination, date, capacity, price)

}

sellTicket(passenger) {
if (this.capacity > 0) {
this.passengers.push(passenger)
this.capacity–
passenger.flights.push({ origin: this.origin, destination: this.destination, date: this.date, price: this.price })
}
if (passenger.age < 18 || passenger.age > 65) {
this.price = this.price - (this.price * 0.20)

}

return new Reservation(this, passenger)
}
}

PremiumFlight

import { Flight } from “./Flight.js”;
import { Reservation } from “./Reservation.js”;

export class PremiumFlight extends Flight {
constructor(origin, destination, date, capacity, price, specialService) {
super(origin, destination, date, capacity, price)
this.specialService = specialService
}

sellTicket(passenger) {
if (this.capacity > 0) {
this.passengers.push(passenger)
this.capacity–
passenger.flights.push({ origin: this.origin, destination: this.destination, date: this.date, price: this.price })
}

this.price += this.specialService
return new Reservation(this, passenger)
}
}

Mi solución…
Hay mucho de lo que no entiendo aún pero pude hacerlos con las instrucciones de la prueba y la ayuda de los aportes pude 😀
Flight

import { Reservation } from "./Reservation";

export class Flight {
  constructor(origin, destination, date, capacity, price) {
    this.origin = origin
    this.destination = destination
    this.date = date
    this.capacity = capacity
    this.price = price
    this.passengers = []
  }

  sellTicket(passenger) {
    if (this.capacity > 0) {
      this.passengers.push({
        fullName: `${passenger.name} ${passenger.lastName}`,
        age: passenger.age
      })
      passenger.flights.push({
        origin: this.origin,
        destination: this.destination,
        date: this.date,
        price: this.price
      })
      this.capacity--
      return new Reservation(this, passenger)
    }
  }
}

Passenger

export class Passenger {
  constructor(name, lastName, age) {
    this.name = name
    this.lastName = lastName
    this.age = age
    this.flights = []
  }
} 

Reservation

export class Reservation {
  constructor(flight, passenger) {
    this.flight = flight
    this.passenger = passenger
  }

  reservationDetails() {
    return {
      origin: this.flight.origin,
      destination: this.flight.destination,
      date: this.flight.date,
      reservedBy: `${this.passenger.name} ${this.passenger.lastName}`
    }
  }
} 

PremiumFlight

import { Flight } from "./Flight";
import { Reservation } from "./Reservation";

export class PremiumFlight extends Flight {
  constructor(origin, destination, date, capacity, price, specialService) {
    super(origin, destination, date, capacity, price + specialService)
  }
}

EconomicFlight

import { Flight } from "./Flight";
import { Reservation } from "./Reservation";

export class EconomicFlight extends Flight {
  constructor(origin, destination, date, capacity, price) {
    super(origin, destination, date, capacity, price)
  }
  
  sellTicket(passenger) {
    if (passenger.age < 18 || passenger.age > 65) {
      this.price = this.price*0.8
    } 
    return super.sellTicket(passenger)
  }
}

mmm

import { Flight } from "./Flight";
import { Reservation } from "./Reservation";

export class EconomicFlight extends Flight {
  constructor(origin, destination, date, capacity, price) {
    super(origin, destination, date, capacity, price);
  }
  sellTicket(passenger) {
    if (this.capacity > 0) {
      if (passenger.age < 18 || passenger.age > 65) {
        this.price -= this.price * 0.2;
      }
      this.passengers.push(passenger);
      passenger.addFlight(this);
      const reservation = new Reservation(this, passenger);
      return reservation;
    }
  }
}
import { Reservation } from "./Reservation";

export class Flight {
  constructor(origin, destination, date, capacity, price) {
    this.origin = origin;
    this.destination = destination;
    this.date = date;
    this.capacity = capacity;
    this.price = price;
    this.passengers = [];
  }

  sellTicket(passenger) {
    if (this.capacity > 0) {
      this.passengers.push({ fullName: `${passenger.name} ${passenger.lastName}`, age: passenger.age });
      passenger.addFlight(this);
      this.capacity -= 1;
      const reservation = new Reservation(this, passenger);
      return reservation;
    }
  }
} 
export class Passenger {
  constructor(name, lastName, age) {
    this.name = name;
    this.lastName = lastName;
    this.age = age;
    this.flights = [];
  }

  addFlight(flight) {
    this.flights.push({
      origin: flight.origin,
      destination: flight.destination,
      date: flight.date,
      price: flight.price
    });
  }
}
import { Flight } from "./Flight";
import { Reservation } from "./Reservation";

export class PremiumFlight extends Flight {
  constructor(origin, destination, date, capacity, price, specialService) {
    super(origin, destination, date, capacity, price);
    this.specialService = specialService;
  }

  sellTicket(passenger) {
    if (this.capacity > 0) {
      this.passengers.push(passenger);
      this.price += this.specialService;
      const reservation = new Reservation(this, passenger);
      return reservation;
    }
  }
}
export class Reservation {
  constructor(flight, passenger) {
    this.flight = flight;
    this.passenger = passenger;
  }

  reservationDetails() {
    return {
      origin: this.flight.origin,
      destination: this.flight.destination,
      date: this.flight.date,
      reservedBy: `${this.passenger.name} ${this.passenger.lastName}`/* name passenger */
    }
  }
} 

Hola, me gustaría compartir mi solución al reto.

Reservation

export class Reservation {
  constructor(flight, passenger) {
    this.flight = flight;
    this.passenger = passenger;
  }

  reservationDetails() {
    return {
      origin: this.flight.origin,
      destination: this.flight.destination,
      date: this.flight.date,
      reservedBy: this.passenger.getFullName()
    }
  }
}

Passenger

export class Passenger {
  constructor(name, lastName, age) {
    this.name = name;
    this.lastName = lastName;
    this.age = age;
    this.flights = []
  }

  addFlight(flight) {
    this.flights.push(flight)
  }

  getFullName() {
    return `${this.name} ${this.lastName}`
  }
}

Flight

export class Flight {
  constructor(origin, destination, date, capacity, price) {
    this.origin = origin;
    this.destination = destination;
    this.date = date;
    this.capacity = capacity;
    this.price = price;
    this.passengers = [];
  }

  sellTicket(passenger) {
    if (this.capacity > 0) {
      this.capacity--;
      let fullName = passenger.getFullName();
      let age = passenger.age;
      this.passengers.push({ fullName, age })
      let { origin, destination, date, price } = this;
      passenger.addFlight({ origin, destination, date, price })
      return new Reservation(this, passenger)
    }
  }
}

PremiumFlight

export class PremiumFlight extends Flight {
  constructor(origin, destination, date, capacity, price, specialService) {
    let newPrice = price + specialService;
    super(origin, destination, date, capacity, newPrice);
    this.specialService = specialService;
  }

}

EconomicFlight

export class EconomicFlight extends Flight {
  sellTicket(passenger) {
    let price = this.price;
    if (passenger.age < 18 || passenger.age > 65) {
      price -= (price * 0.2)
    }
    if (this.capacity > 0) {
      this.capacity--;
      let fullName = passenger.getFullName();
      let age = passenger.age;
      this.passengers.push({ fullName, age })
      let { origin, destination, date } = this;
      let flightData = { origin, destination, date, price };
      passenger.addFlight(flightData)
      return new Reservation(flightData, passenger)
    }
  }
}

Hola, dejo mi solucion,

🛴✨
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
📍

reservations.js

export class Reservation {
  constructor(flight, passenger) {
    this.flight = flight;
    this.passenger = passenger;
    // Tu código aquí 👈
  }

  reservationDetails() {
    // console.log('passenger', this.passenger);
    return {
      origin: this.flight.origin,
      destination: this.flight.destination,
      date: this.flight.date,
      reservedBy: `${this.passenger.name} ${this.passenger.lastName}` 
    }
    // Tu código aquí 👈
  }
}  

passenger.js

export class Passenger {
  // Tu código aquí 👈
  constructor(name, lastName, age) {
    // Tu código aquí 👈
    this.name = name;
    this.lastName = lastName;
    this.age = age;
    this.flights = [];
  }
}

flight.js

import { Reservation } from "./Reservation";

export class Flight {
  constructor(origin, destination, date, capacity, price) {
    // Tu código aquí 👈
    this.origin = origin;
    this.destination = destination;
    this.date = date;
    this.capacity = capacity;
    this.price = price;
    this.passengers = [];
  }
  sellTicket(passenger) {
    // Tu código aquí 👈
    if (this.capacity > 0) {
      this.passengers.push({
        age: passenger.age,
        fullName: `${passenger.name} ${passenger.lastName}`
      });
      passenger.flights.push({
        origin: this.origin,
        destination: this.destination,
        date: this.date,
        price: this.price,
      })
      this.capacity--;

      return new Reservation(this, passenger); 
    }
  }
}

econommicFlight.js

import { Flight } from "./Flight";
import { Reservation } from "./Reservation";

export class EconomicFlight extends Flight {
  constructor(origin, destination, date, capacity, price, specialService) {
    super(origin, destination, date, capacity, price)
    this.specialService = specialService;
  }

  sellTicket(passenger) {
    // Tu código aquí 👈
    if (this.capacity > 0) {
      this.passengers.push({
        age: passenger.age,
        fullName: `${passenger.name} ${passenger.lastName}`
      });
      this.price = passenger.age < 18 || passenger.age > 65 ? this.price - (this.price * 0.2) : this.price;
      passenger.flights.push({
        origin: this.origin,
        destination: this.destination,
        date: this.date,
        price: this.price
      })
      this.capacity--;
      return new Reservation(this, passenger);
    }
  }
} 

premiumFlight.js

import { Flight } from "./Flight";
import { Reservation } from "./Reservation";

export class PremiumFlight extends Flight {
  constructor(origin, destination, date, capacity, price, specialService) {
    super(origin, destination, date, capacity, price)
    this.specialService = specialService;
  }

  sellTicket(passenger) {
    // Tu código aquí 👈
    if (this.capacity > 0) {
      this.passengers.push({
        age: passenger.age,
        fullName: `${passenger.name} ${passenger.lastName}`
      });
      this.price += this.specialService;
      passenger.flights.push({
        origin: this.origin,
        destination: this.destination,
        date: this.date,
        price: this.price
      })
      this.capacity--;
      return new Reservation(this, passenger);
    }
  }
}

Solución… 😄
.
Buen reto, para resolver el ejercicio debe de implementarse las clases correspondientes, y tener cuidado con el formato de los objetos que se agregan a los distintos arrays que se mencionan en el reto.
.
Una manera bastante útil es la de descomponer un objeto y obtener sus propiedades, para después crear un objeto nuevo a partir de esas propiedades.
.
Ejemplo:
.

const { prop1, prop2, prop3, prop4 } = objetoConMasProps;
const nuevoObjeto = {
      prop1,
      prop2,
      prop3,
      prop4
    };

.
EconomicFlight.js:
.

import { Flight } from "./Flight";
import { Reservation } from "./Reservation";

export class EconomicFlight extends Flight {
  constructor(origin, destination, date, capacity, price) {
    super(origin, destination, date, capacity, price);
  }

  sellTicket(passenger) {
    if (this.capacity > 0) {
      this.passengers.push({
        fullName: `${passenger.name} ${passenger.lastName}`,
        age: passenger.age
      });
      this.capacity--;

      if (passenger.age < 18 || passenger.age > 65) {
        this.price *= 0.8;
      }

      passenger.addFlight(this);
      return new Reservation(this, passenger);
    }
  }
}

.
Flight.js:
.

import { Reservation } from "./Reservation";

export class Flight {
  constructor(origin, destination, date, capacity, price) {
    this.origin = origin;
    this.destination = destination;
    this.date = date;
    this.capacity = capacity;
    this.price = price;
    this.passengers = [];
  }

  sellTicket(passenger) {
    if (this.capacity > 0) {
      this.passengers.push({
        fullName: `${passenger.name} ${passenger.lastName}`,
        age: passenger.age
      });
      this.capacity--;

      passenger.addFlight(this);
      return new Reservation(this, passenger);
    }
  }
}

.
Passenger.js:
.

export class Passenger {
  constructor(name, lastName, age) {
    this.name = name;
    this.lastName = lastName;
    this.age = age;
    this.flights = [];
  }

  addFlight(flight) {
    const { origin, destination, date, price } = flight;
    this.flights.push({
      origin,
      destination,
      date,
      price
    });
  }
}

.
PremiumFlight.js:
.

import { Flight } from "./Flight";
import { Reservation } from "./Reservation";

export class PremiumFlight extends Flight {
  constructor(origin, destination, date, capacity, price, specialService) {
    super(origin, destination, date, capacity, price);
    this.specialService = specialService;
  }
  
  sellTicket(passenger) {
    if (this.capacity > 0) {
      this.passengers.push({
        fullName: `${passenger.name} ${passenger.lastName}`,
        age: passenger.age
      });
      this.capacity--;

      this.price += this.specialService;
      passenger.addFlight(this);
      return new Reservation(this, passenger);
    }
  }
}

.
Reservation.js:
.

export class Reservation {
  constructor(flight, passenger) {
    this.flight = flight;
    this.passenger = passenger;
  }

  reservationDetails() {
    const { origin, destination, date } = this.flight;
    const { name, lastName } = this.passenger;

    return {
      origin,
      destination,
      date,
      reservedBy: `${name} ${lastName}`
    }
  }
}

Listo.

Flight.js

import { Reservation } from "./Reservation";

export class Flight {
  constructor(origin, destination, date, capacity, price) {
    this.origin = origin;
    this.destination = destination;
    this.date = date;
    this.capacity = capacity;
    this.price = price;
    this.passengers = [];
  }

  sellTicket(passenger) {
    if (this.capacity > 0) {
      this.capacity--;
      this.passengers.push({ fullName: passenger.name + " " + passenger.lastName, age: passenger.age });
      passenger.addFlight(this.origin, this.destination, this.date, this.price);
      const reservar = new Reservation(this, passenger);
      return reservar;
    }
  }
}

Passenger.js

export class Passenger {
  constructor(name, lastName, age) {
    this.name = name;
    this.lastName = lastName;
    this.age = age;
    this.flights = [];
  }
  addFlight(origin, destination, date, price) {
    this.flights.push({ origin, destination, date, price });
  }
}

Reservation.js

export class Reservation {
  constructor(flight, passenger) {
    this.flight = flight;
    this.passenger = passenger;
  }

  reservationDetails() {
    return { origin: this.flight.origin, destination: this.flight.destination, date: this.flight.date, reservedBy: this.passenger.name + " " + this.passenger.lastName }
  }
}  

EconomicFlight.js

import { Flight } from "./Flight";
import { Reservation } from "./Reservation";

export class EconomicFlight extends Flight {
  constructor(origin, destination, date, capacity, price) {
    super(origin, destination, date, capacity, price);
  }
  sellTicket(passenger) {
    if (passenger.age < 18 || passenger.age > 60) {
      this.price -= (this.price * .20);
    }
    return super.sellTicket(passenger);
  }
}

PremiumFlight.js

import { Flight } from "./Flight";
import { Reservation } from "./Reservation";

export class PremiumFlight extends Flight {
  constructor(origin, destination, date, capacity, price, specialService) {
    super(origin, destination, date, capacity, price);
    this.specialService = specialService;
    this.price += specialService;
  }
}

MI SOLUCION 💪
Algo que no se menciona a la hora de agregar un pasajero a la lista de pasajeros, es que, el pasajero que se agrega debe de tener solo dos atributos los cuales son:

fullName
age

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
class Flight

import { Reservation } from "./Reservation";

export class Flight {
  constructor(origin, destination, date, capacity, price) {
    this.origin = origin;
    this.destination = destination;
    this.date = date;
    this.capacity = capacity;
    this.price = price;
    this.passengers = [];
  }

  sellTicket(passenger) {
    if (this.capacity > 0) {
      this.passengers.push({
        fullName: `${passenger.name} ${passenger.lastName}`,
        age: passenger.age
      });
      passenger.addFlight(this);
      this.capacity--;
      return new Reservation(this, passenger);
    }
  }
}

class Passenger

export class Passenger {
  constructor(name, lastName, age) {
    this.name = name;
    this.lastName = lastName;
    this.age = age;
    this.flights = [];
  }

  addFlight(flight) {
    this.flights.push({
      origin: flight.origin,
      destination: flight.destination,
      date: flight.date,
      price: flight.price
    });
  }
}

class Reservation

export class Reservation {
  constructor(flight, passenger) {
    this.flight = flight;
    this.passenger = passenger;
  }

  reservationDetails() {
    return {
      origin: this.flight.origin,
      destination: this.flight.destination,
      date: this.flight.date,
      reservedBy: `${this.passenger.name} ${this.passenger.lastName}`
    };
  }
} 

class PremiumFlight

import { Flight } from "./Flight";
import { Reservation } from "./Reservation";

export class PremiumFlight extends Flight {
  constructor(origin, destination, date, capacity, price, specialService) {
    super(origin, destination, date, capacity, price);
    this.specialService = specialService;
  }

  sellTicket(passenger) {
    this.price += this.specialService;
    return super.sellTicket(passenger);
  }
}

class EconomicFlight

import { Flight } from "./Flight";
import { Reservation } from "./Reservation";

export class EconomicFlight extends Flight {
  constructor(origin, destination, date, capacity, price) {
    super(origin, destination, date, capacity, price);
    this.truePrice = price;
  }

  sellTicket(passenger) {
    this.price = passenger.age < 18 || passenger > 65 ? this.price - this.price * .2 : this.truePrice;
    return super.sellTicket(passenger);
  }
}

Dejo mi solución:
.
.
.
.
.
.
.
.
.
.
Flight.js

import { Reservation } from "./Reservation";

export class Flight {
  constructor(origin, destination, date, capacity, price) {
    // Tu código aquí 👈
    this.origin = origin;
    this.destination = destination;
    this.date = date;
    this.capacity = capacity;
    this.price = price;
    this.passengers = [];
    this.tempPrice = price;
  }

  sellTicket(passenger) {
    // Tu código aquí 👈
    if (this.capacity == 0) return;
    
    this.passengers.push({
      fullName: `${passenger.name} ${passenger.lastName}`,
      age: passenger.age,
    });

    const flight = {
      origin: this.origin,
      destination: this.destination,
      date: this.date,
      price: this.tempPrice,
    }
    passenger.flights.push(flight);

    this.tempPrice = this.price;
    this.capacity--;

    return new Reservation(flight, passenger);
  }
}

En el constructor se agregó el atributo tempPrice con el valor del precio original y servirá para realizarle las modificaciones correspondientes.
En la función sellTicket, luego de asignarle el vuelo al pasajero, se le devuelve el valor original a tempPrice por si ha sido modificado.

EconomicFlight.js

import { Flight } from "./Flight";
import { Reservation } from "./Reservation";

export class EconomicFlight extends Flight {
  sellTicket(passenger) {
    // Tu código aquí 👈
    if (passenger.age < 18 || passenger.age > 65) {
      this.tempPrice *= 0.8;
    }
    return super.sellTicket(passenger);
  }
}

PremiunFlight.js

import { Flight } from "./Flight";
import { Reservation } from "./Reservation";

export class PremiumFlight extends Flight {
  constructor(origin, destination, date, capacity, price, specialService) {
    // Tu código aquí 👈
    super(origin, destination, date, capacity, price);
    this.specialService = specialService;
  }

  sellTicket(passenger) {
    // Tu código aquí 👈
    this.tempPrice = this.price + this.specialService;
    return super.sellTicket(passenger);
  }
}

Passenger.js

export class Passenger {
  // Tu código aquí 👈
  constructor(name, lastName, age) {
    this.name = name;
    this.lastName = lastName;
    this.age = age;
    this.flights = [];
  }
}

Reservation.js

export class Reservation {
  constructor(flight, passenger) {
    // Tu código aquí 👈
    this.flight = flight;
    this.passenger = passenger;
  }

  reservationDetails() {
    // Tu código aquí 👈
    const { origin, destination, date } = this.flight;
    const { name, lastName } = this.passenger;

    return {
      origin,
      destination,
      date,
      reservedBy: `${name} ${lastName}`,
    }
  }
} 

Buen reto, tienen razón, sufrí un poco por no leer con cuidado cada indicación, omití la parte del retorno de cada sellTicket(), yo estaba retornando this y tenía que retornar un objeto Reseration, solo por esito me rompí la cabeza pero ya está, aquí les comparto mi solución.

Código de EconomicFlight.js

import { Flight } from "./Flight";
import { Reservation } from "./Reservation";

export class EconomicFlight extends Flight {

  sellTicket(passenger) {
    if (this.capacity > 0) {
      if (passenger.age < 18 || passenger.age > 65) {
        this.price = parseInt(this.price - (this.price * 0.2));
      }
      this.passengers.push({ fullName: passenger.name + " " + passenger.lastName, age: passenger.age });

      passenger.flights.push({
        origin: this.origin,
        destination: this.destination,
        date: this.date,
        price: this.price,
      });
      this.capacity--;
      return new Reservation(this, passenger);
    }
   
  }
}

Código de Flight.js

import { Reservation } from "./Reservation";

export class Flight {
  constructor(origin, destination, date, capacity, price) {
    this.origin = origin;
    this.destination = destination;
    this.date = date;
    this.capacity = capacity;
    this.price = price;
    this.passengers = [];
  }

  sellTicket(passenger) {
    if (this.capacity > 0) {
      this.passengers.push({ fullName: passenger.name + " " + passenger.lastName, age: passenger.age });
      passenger.flights.push({
        origin: this.origin,
        destination: this.destination,
        date: this.date,
        price: this.price
      });
      this.capacity--;
      return new Reservation(this, passenger);
    }

  }
}

Código de Passenger.js

export class Passenger {
  constructor(name, lastName, age) {
    this.name = name;
    this.lastName = lastName;
    this.age = age;
    this.flights = [];
  }
}

Código de PremiumFlights.js

import { Flight } from "./Flight";
import { Reservation } from "./Reservation";

export class PremiumFlight extends Flight {
  constructor(origin, destination, date, capacity, price, specialService) {
    super(origin, destination, date, capacity, price);
    this.specialService = specialService;
  }

  sellTicket(passenger) {

    if (this.capacity > 0) {
      this.passengers.push({ fullName: passenger.name + " " + passenger.lastName, age: passenger.age });
      this.price += this.specialService;
      passenger.flights.push({
        origin: this.origin,
        destination: this.destination,
        date: this.date,
        price: this.price
      });
      this.capacity--;
      return new Reservation(this, passenger);
    }
  }
}

Y finalmente el código de la famosa clase Reservatión.

export class Reservation {
  constructor(flight, passenger) {
    if (flight.capacity > 0) {
      this.flight = flight;
      this.passenger = passenger;
    }
  }

  reservationDetails() {

    return {
      origin: this.flight.origin,
      destination: this.flight.destination,
      date: this.flight.date,
      reservedBy: `${this.passenger.name} ${this.passenger.lastName}`
    };
  }
} 

Mi Solución
*
*
*
*
*
*
*

EconomicFlight

import { Flight } from "./Flight";

export class EconomicFlight extends Flight {
  constructor(origin, destination, date, capacity, price) {
    super(origin, destination, date, capacity, price)
  }
  sellTicket(passenger) {
    if (passenger.age < 18 || passenger.age > 65 ) {
      this.price -= (this.price * 20) / 100
    }
    return super.sellTicket(passenger)
  }
}

Flight

import { Reservation } from "./Reservation";

export class Flight {
  constructor(origin, destination, date, capacity, price) {
    this.origin = origin
    this.destination = destination
    this.date = date
    this.capacity = capacity
    this.price = price
    this.passengers = []
  }

  sellTicket(passenger) {
    if (this.capacity) {
      this.capacity--
      passenger.addFlight(this)
      this.passengers.push({
        fullName: `${passenger.name} ${passenger.lastName}`,
        age: passenger.age
      })
      return new Reservation(this, passenger)
    }

  }
} 

Passenger

export class Passenger {
  // Tu código aquí 👈
  constructor(name, lastname, age) {
    this.name  = name
    this.lastName  = lastname
    this.age = age
    this.flights = []
  }

  addFlight(flight) {
    this.flights.push({
      origin: flight.origin, 
      destination: flight.destination, 
      date: flight.date, 
      price: flight.price,
    })
  }
}

PremiumFlight

import { Flight } from "./Flight";

export class PremiumFlight extends Flight {
  constructor(origin, destination, date, capacity, price, specialService) {
    super(origin, destination, date, capacity, price)
    this.specialService = specialService
  }

  sellTicket(passenger) {
    this.price += this.specialService
    return super.sellTicket(passenger)
  }
}

PremiumFlight

import { Flight } from "./Flight";

export class PremiumFlight extends Flight {
  constructor(origin, destination, date, capacity, price, specialService) {
    super(origin, destination, date, capacity, price)
    this.specialService = specialService
  }

  sellTicket(passenger) {
    this.price += this.specialService
    return super.sellTicket(passenger)
  }
}

Reservation

export class Reservation {
  constructor(flight, passenger) {
    this.flight = flight
    this.passenger = passenger
  }

  reservationDetails() {
    return {
      origin: this.flight.origin,
      destination: this.flight.destination,
      date: this.flight.date,
      reservedBy: `${this.passenger.name} ${this.passenger.lastName}`
    }
  }
} 

Mi solución:
.
.
.
.
.
.
EconomicFlight.js

import { Flight } from "./Flight"

export class EconomicFlight extends Flight {
  constructor(origin, destination, date, capacity, price) {
    super(origin, destination, date, capacity, price)
  }
  sellTicket(passenger) {
    if (passenger.age < 18 || passenger.age > 65) {
      this.price *= 0.8
    }
    return super.sellTicket(passenger)
  }
}

Flight.js

import { Reservation } from "./Reservation"

export class Flight {
  constructor(origin, destination, date, capacity, price) {
    this.origin = origin
    this.destination = destination
    this.date = date
    this.capacity = capacity
    this.price = price
    this.passengers = []
  }

  sellTicket(passenger) {
    if (this.capacity) {
      this.passengers.push({
        fullName: `${passenger.name} ${passenger.lastName}`,
        age: passenger.age
      })
      passenger.flights.push({
        origin: this.origin,
        destination: this.destination,
        date: this.date,
        price: this.price 
      })
      const reservation = new Reservation(this, passenger)
      this.capacity--
      return reservation
    }
  }
} 

Passenger.js

export class Passenger {
  constructor(name, lastName, age) {
    this.name = name
    this.lastName = lastName
    this.age = age
    this.flights = []
  }
}

PremiumFlight.js

import { Flight } from "./Flight"

export class PremiumFlight extends Flight {
  constructor(origin, destination, date, capacity, price, specialService) {
    super(origin, destination, date, capacity, price)
    this.specialService = specialService
  }

  sellTicket(passenger) {
    this.price += this.specialService
    return super.sellTicket(passenger)
  }
}

Reservation.js

export class Reservation {
  constructor(flight, passenger) {
    this.flight = flight
    this.passenger = passenger
  }

  reservationDetails() {
    return {
      origin: this.flight.origin,
      destination: this.flight.destination,
      date: this.flight.date,
      reservedBy: `${this.passenger.name} ${this.passenger.lastName}`
    }
  }
} 

Mi solución

Dentro de la clase Flight en la función sellTicket(), cada que se agrega un pasajero a array de passengers[] se debe de restar uno a la capacidad del vuelo, al agregar al array de pasajeros, solo busca dos propiedades(edad y nombre completo).Igual que el pasajero para guardar el vuelo dentro del array de flights[] solo requiere 4 propiedades(origen, destino,fecha y precio).

Al final de la función retorno la clase reservación pasando por argumento this(“refiriéndome a la clase Flight o si es heredada, a PremiumFlight o a EconomicFlight”) y passenger.

Dentro de la clase Reservation, el método reservationDetails() debe de retornar una clase con las propiedades del vuelo y del pasajero.

Como EconomicFlight y PremiumFlight extienden de Flight, el método sellTicket() de cada uno hace sus respectivas funciones con el precio del vuelo y luego retorno la llamada a la función sellTicket() del padre para que devuelva los datos de la reservación.

Flight.js

import { Reservation } from "./Reservation";

export class Flight {
  constructor(origin, destination, date, capacity, price) {
    this.origin = origin;
    this.destination = destination;
    this.date = date;
    this.capacity = capacity;
    this.price = price;
    this.passengers = [];
  }

  sellTicket(passenger) {
    if (this.capacity > 0) {
      this.passengers.push({ age: passenger.age, fullName: passenger.getFullName()});
      passenger.flights.push({
        origin : this.origin,
        destination : this.destination,
        date : this.date,
        price: this.price
      });
      this.capacity -= 1;
      return new Reservation(this, passenger);
    }
  }
}

Passenger.js

export class Passenger {
  constructor(name, lastName, age) {
    this.name = name;
    this.lastName = lastName;
    this.age = age;
    this.flights = [];
  }
  getFullName() {
    return this.name+' '+this.lastName;
  }
}

EconomicFlight.js

import { Flight } from "./Flight";

export class EconomicFlight extends Flight {
  constructor(origin, destination, date, capacity, price,) {
    super(origin, destination, date, capacity, price);
  }
  sellTicket(passenger) {
    if (passenger.age < 18 || passenger.age > 65) {
      this.price = this.price * .8;
    }
    return super.sellTicket(passenger);
  }
}

PremiumFlight.js

import { Flight } from "./Flight";

export class PremiumFlight extends Flight {
  constructor(origin, destination, date, capacity, price, specialService) {
    super(origin, destination, date, capacity, price);
    this.specialService = specialService;
  }
  sellTicket(passenger) {
    this.price += this.specialService;
    return super.sellTicket(passenger);
  }
}

Reservation.js

export class Reservation {
  constructor(flight, passenger) {
    this.flight = flight;
    this.passenger = passenger;
  }
  reservationDetails() {
    return {
      origin: this.flight.origin,
      destination: this.flight.destination,
      date: this.flight.date,
      reservedBy: this.passenger.getFullName()
    };
  }
} 

Auch, tengo que admitir que revisé las respuestas de Luis y David para ver porque rayos “la reservacion no se hacia”

Siento ganas de volver a intentarlo de cero en un futuro a ver que tal me va
.
.
.
.
.
.
.
Economic

import { Flight } from "./Flight";

export class EconomicFlight extends Flight {
  constructor(origin, destination, date, capacity, price) {
    super(origin, destination, date, capacity, price);
  }

  sellTicket(passenger) {
    if (passenger.age < 18 || passenger.age > 65) {
      this.price = (this.price - this.price * 0.20);
    }
    return super.sellTicket(passenger)
  }
}

Fligth

import { Reservation } from "./Reservation";

export class Flight {
  constructor(origin, destination, date, capacity, price) {
    this.origin = origin;
    this.destination = destination;
    this.date = date;
    this.capacity = capacity;
    this.price = price;
    this.passengers = [];
  }

  sellTicket(passenger) {
    if (this.capacity > 0) {
      this.passengers.push({
        fullName: `${passenger.name} ${passenger.lastName}`,
        age: passenger.age
      })
      passenger.addflight(this);
      this.capacity -= 1;

      let reservation = new Reservation(this, passenger);
      return { reservation };
    }
  }
}

Passenger

export class Passenger {
  constructor(name, lastName, age) {
    this.name = name;
    this.lastName = lastName;
    this.age = age;
    this.flights = [];
  }
  addflight(fligth) {
    this.flights.push({
      origin: fligth.origin,
      destination: fligth.destination,
      date: fligth.date,
      price: fligth.price
    })
  };
}

Premiun (con el truco de David)

import { Flight } from "./Flight";

export class PremiumFlight extends Flight {
  constructor(origin, destination, date, capacity, price, specialService) {
    super(origin, destination, date, capacity, price);
    this.price = this.price + specialService;
  }
}

Reservation

export class Reservation {
  constructor(flight, passenger) {
    this.flight = flight,
    this.passenger = passenger;
  }

  reservationDetails() {
    return {
      origin: flight.origin,
      destination: flight.destination,
      date: flight.date,
      reservedBy: `${passenger.name} ${passenger.lastName}`,
    }
  }
} 
undefined