隆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

Quedan menos de 24 hrs para aprender Ingl茅s, AI y m谩s a precio especial.

Antes: $249

Currency
$209
Suscr铆bete

Termina en:

0 D铆as
8 Hrs
58 Min
31 Seg

Playground - Sistema de pagos

64/99

Aportes 33

Preguntas 0

Ordenar por:

驴Quieres ver m谩s aportes, preguntas y respuestas de la comunidad?

Con este reto descubr铆 algo interesante y es que si extiendes una clase sobre otra debes siempre debes poner el super constructor aunque no le pases propiedades.

Ahora si dejo mi respuesta abajo.

Soluci贸n:

.
.
.
.
.
.
.
.
.
.

Card.class.js:

import { Pay } from "./Pay.class.js";

export class Card extends Pay {
  constructor(number) {
    super()
    this.number = number
  }

  makePay(quantity) {
    try {
      if (this.number.length !== 16) throw Error('No tiene 16 d铆gitos')

      return {
        ...super.makePay(quantity),
        lastCardNumbers: this.number.slice(-4)
      }
    }
    catch (e) {
      throw Error(e)
    }
  }
}

Cash.class.js:

import { Pay } from "./Pay.class.js";

export class Cash extends Pay {
  makePay(quantity) {
    return super.makePay(quantity)
  }
}

Pay.class.js:

export class Pay {
  makePay(quantity) {
    return {
      realized: true,
      quantity: quantity
    }
  }
}

PayPal.class.js:

import { Pay } from "./Pay.class.js";

export class PayPal extends Pay {
  constructor(email) {
    super()
    this.email = email
  }

  makePay(quantity) {
    return {
      ...super.makePay(quantity),
      platform: "PayPal",
      email: this.email
    }
  }
}

exercise.js:

export function processPay(method, quantity) {
  return method.makePay(quantity)
}

Un reto muy interesante, mi soluci贸n:
馃洝锔
馃洝锔
馃洝锔
馃洝锔
馃洝锔
馃洝锔
馃洝锔
馃洝锔
馃洝锔
馃洝锔
exercise.js

export function processPay(method, quantity) {
  return method.makePay(quantity);
}

PayPal.class.js

import { Pay } from "./Pay.class.js";

export class PayPal extends Pay {
  constructor(email) {
    super();
    this.email = email;
  }
  makePay(quantity) {
    return { ...super.makePay(quantity), platform: "PayPal", email: this.email };
  }
}

Pay.class.js

export class Pay {
  constructor() {
    this.realized = true;
  }
  makePay(quantity) {
    return { realized: this.realized, quantity };
  }
}

Cash.class.js

import { Pay } from "./Pay.class.js";

export class Cash extends Pay {
  constructor() {
    super();
  }
}

Card.class.js

import { Pay } from "./Pay.class.js";

export class Card extends Pay {
  constructor(card) {
    super();
    this.card = card;
  }
  makePay(quantity) {
    if (this.card.length === 16) {
      return { ...super.makePay(quantity), lastCardNumbers: this.card.slice(-4) };
    } else {
      throw Error("Error, la tarjeta debe ser de 16 digitos")
    }
  }
}

馃洝锔忦煕★笍Escudo anti-spoilers馃洝锔忦煕★笍

Mi soluci贸n al reto:

Card.class.js

import { Pay } from "./Pay.class.js";

export class Card extends Pay {

  constructor(cardNumber) {
    super()
    this.cardNumber = cardNumber
  }

  makePay(cantidadAPaga) {
    if (this.cardNumber.length < 16) {
      throw new Error('Error en el longitud de los digitos de la tarjeta')
    }
    return {
      ...super.makePay(cantidadAPaga),
      lastCardNumbers: this.cardNumber.substring(this.cardNumber.length - 4, this.cardNumber.length)
    }
  }
}

Cash.class.js

import { Pay } from "./Pay.class.js";

export class Cash extends Pay {
  constructor() {
    super()
  }
  makePay(cantidadAPaga) {
    return {
      ...super.makePay(cantidadAPaga)
    }
  }
}

Pay.class.js

export class Pay {
  makePay(cantidadAPaga) {
    return {
      realized: true,
      quantity: cantidadAPaga
    }
  }
}

Paypal.class.js

import { Pay } from "./Pay.class.js";

export  class PayPal extends Pay {
  email;

  constructor(email) {
    super()
    this.email = email
  }

  makePay(cantidadAPaga) {
    return {
      ...super.makePay(cantidadAPaga),
      platform: "PayPal",
      email: this.email
    }
  }
}

exercise.js

import { Card } from "./Card.class.js";
import { PayPa } from "./PayPal.class.js";
import { Cash } from "./Cash.class.js";

export function processPay(method, quantity) {
  return method.makePay(quantity)
}

.
. ------------------------------------------------------------ .
. 馃洝锔忦煕★笍馃洝锔廍SCUDO ANTI SPOILER 馃洝锔忦煕★笍馃洝锔 .
. ------------------------------------------------------------ .
.
. Muy interesante este reto, creo que lo hare un par de veces mas para comprenderlo mejor.
.
.

.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.

Card.class.js

import { Pay } from "./Pay.class.js";

export class Card extends Pay {
  constructor(cardNumber) {
    super();
    this.cardNumber = cardNumber;
  }

  makePay(quantity) {
    if (this.cardNumber.length !== 16) {
      throw new Error("N煤mero de tarjeta invalido");
    }
    return {
      ...super.makePay(quantity),
      lastCardNumbers: this.cardNumber.slice(-4)
    };
  }
}

Cash.class.js

import { Pay } from "./Pay.class.js";

export class Cash extends Pay {
  makePay(quantity) {
    return super.makePay(quantity)
  }
}

Pay.class.js

export class Pay {
  makePay(quantity) {
    return {
      realized: true,
      quantity
    }
  }
}

PayPal.class.js

import { Pay } from "./Pay.class.js";

export class PayPal extends Pay {
  constructor(email) {
    super();
    this.email = email;
  }

  makePay(quantity) {
    const pay = super.makePay(quantity);
    pay.platform = "PayPal";
    pay.email = this.email;
    return pay;
  }
}

exercise.js

export function processPay(method, quantity) {
  return method.makePay(quantity)
}
Comparto mi soluci贸n. Nunca se den por vencidos. Poco a poco se llega a diferentes lugares. ```js function processPay(method, quantity) { return method.makePay(quantity); } class Pay { makePay(cantPay) { return { realized: true, quantity: cantPay } } } class PayPal extends Pay { constructor(email) { super(); this.email = email; } makePay(cantPay) { return { realized: true, quantity: cantPay, platform: "PayPal", email: this.email } } } class Card extends Pay { constructor(card) { super(); this.card = card; } makePay(cantPay) { if(this.card.length != 16) { throw new Error("Invalido, debe de tener 16 digitos la tarjeta para validar el pago."); } else { const finishCard = this.card.slice(-4); return { realized: true, quantity: cantPay, lastCardNumbers: `${finishCard}` } } } } class Cash extends Pay { makePay(cantPay) { return { realized: true, quantity: cantPay } } } ```

Desafio completo!


馃洝锔忦煕★笍馃洝锔廍scudo anti spoilers馃洝锔忦煕★笍馃洝锔

Implementa un sistema de pagos usando polimorfismo

Pay.class.js

export class Pay {
  // Tu c贸digo aqu铆 馃憟
  makePay(quantity) {
    return { realized: true, quantity };
  }
}

Cash.class.js

export class Cash extends Pay {
  // Tu c贸digo aqu铆 馃憟
}

Card.class.js

export class Card extends Pay {
  constructor(cardNumber) {
    super();
    this.cardNumber = cardNumber;
  }
  // Tu c贸digo aqu铆 馃憟
  makePay(quantity) {
    if (this.cardNumber.length != 16) {
      throw new Error("Invalid Card Number");
    } else {
      return {
        ...super.makePay(quantity),
        lastCardNumbers: this.cardNumber.substr(12),
      };
    }
  }
}

PayPal.class.js

export class PayPal extends Pay {
  // Tu c贸digo aqu铆 馃憟
  constructor(email) {
    super();
    this.email = email;
  }
  makePay(quantity) {
    return {
      ...super.makePay(quantity),
      platform: "Paypal",
      email: this.email,
    };
  }
}

exercise.js

export function processPay(method, quantity) {
  // Tu c贸digo aqu铆 馃憟
  return method.makePay(quantity);
}

Mi soluci贸n 馃挌

exercise.js

.
.
.

export function processPay(method, quantity) {
  return method.makePay(quantity)
}

Pay.class.js

export class Pay {
  makePay(amount) {
    return {
      realized: true,
      quantity: amount
    }
  }
}

PayPal.class.js

import { Pay } from "./Pay.class.js";

export class PayPal extends Pay {
  constructor(email) {
    super()
    this.email = email
  }
  makePay(amount) {
    return {
      ...super.makePay(amount),
      platform: "PayPal",
      email: this.email
    }
  }
}

Card.class.js

import { Pay } from "./Pay.class.js";

export class Card extends Pay {
  constructor(cardNumber) {
    super()
    this.cardNumber = cardNumber
  }

  makePay(amount) {
    if (this.cardNumber.length !== 16)
      throw new Error('El n煤mero de tarjeta debe ser de 16 d铆gitos')
    return {
      ...super.makePay(amount),
      lastCardNumbers: this.cardNumber.substring(12)
    }
  }
}

y finalmente a Cash no era necesario hacerlo 馃挌

// Card.class.js
export class Card extends Pay {
  constructor(cardNumber) {
    super()
    this.cardNumber = cardNumber
  }
  makePay(qty) {
    if (typeof this.cardNumber !== "string" || this.cardNumber.length !== 16) {
      throw new Error("Invalid Card Number")
    }
    this.lastFourNumbers = this.cardNumber.split("").splice(-4).join("")
    const obj = super.makePay(qty)
    return {
      ...obj,
      lastCardNumbers: this.lastFourNumbers
    }
  }
}
// Cash.class.js
export class Cash extends Pay {
  constructor() {
    super()
  }
  makePay(qty) {
    return super.makePay(qty)
  }
}
// Pay.class.js
export class Pay {
  constructor() {
    this.realized = null // bool
    this.quantity = null // number
  }
  makePay(quantity) {
    this.quantity = quantity
    this.realized = true
    return {
      realized: this.realized,
      quantity: this.quantity
    }
  }
}
// Paypla.class.js
export class PayPal extends Pay {
  constructor(email) {
    super()
    this.email = email
    this.platform = "PayPal"
  }
  makePay(qty) {
    const obj = super.makePay(qty)
    return {
      ...obj,
      email: this.email,
      platform: this.platform
    }
  }
}
// exercise.js
export function processPay(method, quantity) {
  // method -> obj; quantity -> number
  return method.makePay(quantity)
}

pay

export class Pay {
  makePay(cantPay) {
    return {
      realized: true,
      quantity: cantPay
    }
  }
}

PayPal

import { Pay } from "./Pay.class.js";

export class PayPal extends Pay {
  emailReceived;

  constructor(email) {
    super()
    this.emailReceived = email
  }

  makePay(cantPay) {
    return {
      ...super.makePay(cantPay),
      platform: "PayPal",
      email: this.emailReceived
    }
  }
}

Card

import { Pay } from "./Pay.class.js";

export class Card extends Pay {
  card;
  constructor(cardNumber) {
    super();
    this.card = cardNumber;
  }
  makePay(cantPay) {
    if (this.card.length === 16) {
      return {
        ...super.makePay(cantPay),
        lastCardNumbers: this.card.toString().substr(-4)
      }
    } else {
      throw new Error('La tarjeta no tiene la longitud')
    }
  }
}

cash.js

import { Pay } from "./Pay.class.js";

export class Cash extends Pay {
  constructor() {
    super()
  }
  makePay(cantPay) {
    return {
      ...super.makePay(cantPay)
    }
  }
}

exercise.js

import { Card } from "./Card.class.js";
import { PayPa } from "./PayPal.class.js";
import { Cash } from "./Cash.class.js";
import { pay } from "./Pay.class.js";

export function processPay(method, quantity) {
  return method.makePay(quantity);
}

Hola Comparto la soluci贸n al Reto:
鉁呪渽鉁
鉁呪渽鉁
鉁呪渽鉁
鉁呪渽鉁

Pay.class.js

export class Pay {
  makePay(cantidadAPagar) {
    return {
      realized: true,
      quantity: cantidadAPagar,
    }
  }
}

PayPal.class.js

import { Pay } from "./Pay.class.js";

export class PayPal extends Pay {
  constructor(email) {
    super();
    this.email = email;
  }

  makePay(cantidadAPagar) {
    return {
      realized: true,
      quantity: cantidadAPagar,
      platform: "PayPal",
      email: this.email
    }
  }
}

Card.class.js

import { Pay } from "./Pay.class.js";

export class Card extends Pay {
  constructor(numberCard) {
    super();
    this.numberCard = numberCard;
  }

  makePay(cantidadAPagar) {
    if (this.numberCard === undefined || this.numberCard.length !== 16) {
      throw new Error("Numero de Tarjeta invalida");
    }

    const result = super.makePay(cantidadAPagar);
    result.lastCardNumbers = this.numberCard.slice(-4);

    return result;
  }
}

Cash.class.js

import { Pay } from "./Pay.class.js";

export class Cash extends Pay {
  constructor() {
    super();
  }

  makePay(cantidadAPagar) {
    return super.makePay(cantidadAPagar);
  }
}

exercise.js

export function processPay(method, quantity) {
  return method.makePay(quantity);
}


.
.
.
.
.
.

Card.class.js

import { Pay } from "./Pay.class.js";

export class Card extends Pay {
  constructor(cardNumber) {
    super();
    this.cardNumber = cardNumber;
  }

  makePay(quantity) {
    if (this.cardNumber.length != 16) {
      throw new Error("N煤mero de tarjeta inv谩lida.")
    } else {
      return {
        ...super.makePay(quantity),
        lastCardNumbers: this.cardNumber.substring(12, 17)
      }
    }
  }
}

Cash.class.js

import { Pay } from "./Pay.class.js";

export class Cash extends Pay {
  constructor() {
    super();
  }
}

Pay.class.js

export class Pay {
  makePay(quantity) {
    return { realized: true, quantity: quantity}
  }
}

PayPal.class.js

import { Pay } from "./Pay.class.js";

export class PayPal extends Pay {
  constructor(email) {
    super();
    this.email = email;
  }

  makePay(quantity) {
    return { 
      ...super.makePay(quantity),
      platform: "PayPal", 
      email: this.email
    }
  }
}

exercise.class.js

export function processPay(method, quantity) {
  return method.makePay(quantity)
}

Mi soluci贸n:
Nota: Casi muero porque en PayPal.class.js tenia escrito 鈥淧aypal鈥 en lugar de 鈥淧ayPal鈥 con la segunda P tambi茅n en mayus.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

Card.class.js

import { Pay } from "./Pay.class.js";

export class Card extends Pay {
  constructor(cardNumber) {
    super();
    this.cardNumber = cardNumber;
  }
  makePay(quantity) {
    if (this.cardNumber.length != 16) {
      throw new Error("La tarjeta no cumple con tener 16 digitos")
    } else {
      return {
        ...super.makePay(quantity),
      lastCardNumbers: this.cardNumber.slice(-4)
      }
    }
  }

}

Cash.class.js

import { Pay } from "./Pay.class.js";

export class Cash extends Pay {
  makePay(quantity) {
    return super.makePay(quantity);
  }
}

Pay.class.js

export class Pay {
    makePay(quantity) {
      return {
        realized: true,
        quantity: quantity
      }
    }
  }

Paypal.class.js

import { Pay } from "./Pay.class.js";

export class PayPal extends Pay {
  constructor(email) {
    super();
    this.email = email;
  }
  makePay(quantity) {
    return {
      ...super.makePay(quantity),
      platform: "PayPal",
      email: this.email
    }
  }
}

excercise.js

export function processPay(method, quantity) {
    return method.makePay(quantity)
  }

Soluci贸n

class Pay {
  makePay(quantity) {
    return {
      realized: true,
      quantity: `$${quantity}`,
    };
  }
}

class Card extends Pay {
  constructor(cardNumber) {
    super();
    this.cardNumber = cardNumber;
  }

  makePay(quantity) {
    if (!this.cardNumber.length == 16) {
      return new Error("Card number must be 16 characters");
    }
    return {
      ...super.makePay(quantity),
      lastCardNumbers: this.cardNumber.slice(-4),
    };
  }
}
class Cash extends Pay {
  constructor() {
    super();
  }
}
class PayPal extends Pay {
  constructor(email) {
    super();
    this.email = email;
  }

  makePay(quantity) {
    return {
      ...super.makePay(quantity),
      platform: "Paypal",
      email: this.email,
    };
  }
}

function processPay(method, quantity) {
  // Tu c贸digo aqu铆 馃憟
  console.log(method.makePay(quantity));
  return method.makePay(quantity);
}

Aqu铆 mi soluci贸n:
.
.
.
.
.
.
.
.
.
.
.
Pay.class.js

export class Pay {
  makePay(quantity) {
    return {
      realized: true,
      quantity: quantity
    }
  }
}

PayPal.class.js

export class PayPal extends Pay {
  constructor(email) {
    super()
    this.email = email
  }
  makePay(quantity) {
    return {
      ... super.makePay(quantity),
      platform: "PayPal",
      email: this.email
    }
  }
}

Card.class.js

export class Card extends Pay {
  constructor(lastCardNumbers) {
    super()
    this.lastCardNumbers = lastCardNumbers
  }
  makePay(quantity) {
    if (this.lastCardNumbers.length === 16) {
      return {
        ... super.makePay(quantity),
        lastCardNumbers: this.lastCardNumbers.substring(this.lastCardNumbers.length - 4)
      }
    }
    else {
      throw new Error("Error en el n煤mero de tarjeta");
    }

  }
}

cash.class.js

export class Cash extends Pay {
  makePay(quantity) {
    return super.makePay(quantity);
  }
}

exercise.js

export function processPay(method, quantity) {
  return method.makePay(quantity);
};

Soluci贸n.

Pay.class.js

export class Pay {
  // Tu c贸digo aqu铆 馃憟
  constructor() {
    this.realized = true;
  }

  makePay(quantity) {
    return {
      realized: this.realized,
      quantity: quantity
    }
  }
}

PayPal.class.js

import { Pay } from "./Pay.class.js";

export class PayPal extends Pay {
  // Tu c贸digo aqu铆 馃憟
  constructor(email) {
    super();
    this.email = email;
  }

  makePay(quantity) {
    return {
      ...super.makePay(quantity),
      platform: "PayPal",
      email: this.email
    }
  }
}

Card.class.js

import { Pay } from "./Pay.class.js";

export class Card extends Pay {
  // Tu c贸digo aqu铆 馃憟
  constructor(cardNumber) {
    super();
    this.cardNumber = cardNumber;
  }

  makePay(quantity) {
    if (this.cardNumber.length !== 16)
      throw new Error("El numero de la tajeta no tiene 16 digitos");

    return {
      ...super.makePay(quantity),
      lastCardNumbers: this.cardNumber.slice(-4)
    }
  }
}

Cash.class.js

import { Pay } from "./Pay.class.js";

export class Cash extends Pay {
  // Tu c贸digo aqu铆 馃憟
}

exercise.js

export function processPay(method, quantity) {
  // Tu c贸digo aqu铆 馃憟
  return method.makePay(quantity);
}

Aporto la soluci贸n!
.
.
.
.
.
.
.
.
.
.

exercise.js

export function processPay(method, quantity) {
  return method.makePay(quantity)
}

PayPal.class.js

import { Pay } from "./Pay.class.js";

export class PayPal extends Pay {
  constructor(email) {
    super()
    this.email=email
  }

  makePay(quantity) {
    return Object.assign({}, { 'platform': 'PayPal', 'email': this.email }, super.makePay(quantity))
  }
}

Pay.class.js

export class Pay {
  makePay(quantity) {
    return {'realized': true,'quantity':quantity}
  }
}

Cash.class.js

import { Pay } from "./Pay.class.js";

export class Cash extends Pay {
  constructor() {super()}
}

Card.class.js

import { Pay } from "./Pay.class.js";

export class Card extends Pay {
  constructor(cardNumber) {
    super()
    this.cardNumber = cardNumber
  }

  makePay(quantity) {
    if (this.cardNumber.length != 16) throw new Error('El n煤mero de la tarjeta es err贸neo')
    return Object.assign({}, {'lastCardNumbers': this.cardNumber.slice(12, 16)}, super.makePay(quantity))
  }
}

import { Pay } from "./Pay.class.js";

export class Card extends Pay {
  // Tu c贸digo aqu铆 馃憟
  constructor(card) {
    if (card.length !== 16) throw super(new Error("Invalid Card"))
    super({
      lastCardNumbers: card.substr(12)
    })
  }
}

import { Pay } from "./Pay.class.js";

export class Cash extends Pay {
  // Tu c贸digo aqu铆 馃憟
}
export class Pay {
  // Tu c贸digo aqu铆 馃憟
  constructor(payload) {
    this._payload = payload
  }
  makePay(quantity) {
    return {
      realized: true, 
      quantity,
      ...this._payload
    }
  }
}

import { Pay } from "./Pay.class.js";

export class PayPal extends Pay {
  // Tu c贸digo aqu铆 馃憟
  constructor(email) {
    super({
      platform: "PayPal",
      email,
    })
  }
}

export function processPay(method, quantity) {
  // Tu c贸digo aqu铆 馃憟
  return method.makePay(quantity)
}

Ojo que al retornar el objeto de Card la propiedad lastCardNumber en el test lo recibe en plural lastCardNumbers.

Dicho esto aqui dejo mi code:

Pay

export class Pay {
  makePay(quantity) {
    return {
      realized: true,
quantity: quantity}
  }
}

PayPal

import { Pay } from "./Pay.class.js";

export class PayPal extends Pay {
  constructor(email) {
    super()
    this.email = email
  }
  makePay(quantity) {
    return {
      ...super.makePay(quantity),
      "platform": "PayPal",
  "email": this.email
    }
  }
}

Card

import { Pay } from "./Pay.class.js";

export class Card extends Pay {
  constructor(cardNumber) {
    super()
    this.cardNumber = cardNumber
  }
  makePay(quantity) {
      
        if (this.cardNumber.length !== 16) {
          throw new Error('invalid card')
        }
        else {
          return {
            ...super.makePay(quantity),
            lastCardNumbers: this.cardNumber.substring(12, 16)
          }
        }
      }
    }

Cash

import { Pay } from "./Pay.class.js";

export class Cash extends Pay {
  constructor() {
    super()
  }
  makePay(quantity) {
    return super.makePay(quantity)
  }
}

Que susto! No me di cuenta que estaba dividido las clases por archivos en el PlayGround鈥aja, aqu铆 dejo mi aporte鈥 馃槂

function processPay(method, quantity) {
    // Tu c贸digo aqu铆 馃憟
     
    
   return  method.makePay(quantity);
  }
class Pay{
    constructor() {
        this._lastCardNumber;       
    }
    makePay(quantity){    
    
        return {
            realized: true,
            quantity,           
        };
    }
}  
class PayPal extends Pay{
    constructor(mail) {
        super();
        this._mail= mail;
       
    }

    makePay(quantity){
        
        return{
            ...super.makePay(quantity),
            platform: "PayPal",
            email: `${this._mail}` 
        }       
    }
}
class Card extends Pay{
    constructor(card) {
        super();        
        this._card=card;

    }
    makePay(quantity){
       
        if(this._card.length===16){    
            this._lastCardNumber=this._card.slice(-4);              
           return {...super.makePay(quantity), lastCardNumbers: this._lastCardNumber};          
        }else{
            throw new Error("No tiene 16 d铆gitos")
        }
    }
}
class Cash extends Pay{
   constructor() {
    super();
   }

}

Mi solucion:
.
.
.
.
.
.
.
.
.
.

Card.class.js

import { Pay } from "./Pay.class.js";

export class Card extends Pay {
  constructor(cardNum) {
    super();
    this.cardNum = cardNum;
  }

  makePay(quantity) {
    if (!this.cardNum || this.cardNum.length !== 16) throw new Error('The length of the number entered does not match a card number.');

    return {
      ...super.makePay(quantity),
      lastCardNumbers: this.cardNum.slice(-4)
    }
  }
}

Cash.class.js

import { Pay } from "./Pay.class.js";

export class Cash extends Pay {

}

Pay.class.js

export class Pay {
  makePay(quantity) {
    return {
      realized: true,
      quantity
    }
  }
}

PayPal.class.js

import { Pay } from "./Pay.class.js";

export class PayPal extends Pay {
  constructor(email) {
    super();
    this.email = email;
  }

  makePay(quantity) {
    return {
      ...super.makePay(quantity),
      platform: 'PayPal',
      email: this.email
    }
  }
}

exercise.js

export function processPay(method, quantity) {
  return method.makePay(quantity);
}
export function processPay(method, quantity) {
  return method.makePay(quantity);
}

MI APORTE 馃挭
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
Class pay

export class Pay {
  makePay(quantity) {
    return {
      realized: true,
      quantity: quantity
    }
  }
}

Clas PayPal

import { Pay } from "./Pay.class.js";

export class PayPal extends Pay {
  constructor(email) {
    super();
    this.email = email;
  }

  makePay(quantity) {
    return {
      ...super.makePay(quantity),
      platform: "PayPal",
      email: this.email
    };
  }
}

Class Card

import { Pay } from "./Pay.class.js";

export class Card extends Pay {
  constructor(cardNumber) {
    super();
    this.cardNumber = cardNumber;
  }

  makePay(quantity) {
    if (this.cardNumber.length === 16) {
      return {
        ...super.makePay(quantity),
        lastCardNumbers: this.cardNumber.slice(-4)
      };
    }
    throw new Error("ERROR NUMBER CARD INVALID");
  }
}

function processPay

export function processPay(method, quantity) {
  return method.makePay(quantity);
}

Mi soluci贸n:
.
.
.
.
.
.
.
.
.
.
.
Pay.class.js

export class Pay {
  constructor() {
    this.realized = true
  }
  makePay(quantity) {
    return { ...this, quantity }
  }
}

PayPal.class.js

import { Pay } from "./Pay.class.js";

export class PayPal extends Pay {
  constructor(email) {
    super()
    this.email = email
    this.platform = "PayPal"
  }

  makePay(quantity) {
    return { ...this, quantity }
  }
}

Card.class.js

import { Pay } from "./Pay.class.js";

export class Card extends Pay {
  constructor(number) {
    super()
    this.number = number
  }

  makePay(quantity) {
    if (this.number.length !== 16)
      throw new Error('Enter a valid number')

    const lastCardNumbers = this.number.slice(12)
    const { realized } = this
    return { realized, quantity, lastCardNumbers }
  }
}

Cash.class.js

import { Pay } from "./Pay.class.js";

export class Cash extends Pay {}

exercise.js

export function processPay(method, quantity) {
  return method.makePay(quantity)
}

Hola, dejo mi solucion

馃洿鉁
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
馃搷

function processPay(method, quantity) {
  // Tu c贸digo aqu铆 馃憟
  return method.makePay(quantity)
} 

class Pay {
  makePay(cantidadAPagar) {
    return {
      realized: true,
      quantity: cantidadAPagar
    }
  }
}

class PayPal extends Pay{
  constructor(email) {
    super();
    this.email = email;
  }
  makePay(cantidadAPagar) {
    return {
      ...super.makePay(cantidadAPagar),
      platform: "PayPal",
      email: this.email
    }
  }
}
class Card extends Pay{
  constructor(tarjeta) {
    super();
    this.tarjeta = tarjeta;
  }
  makePay(cantidadAPagar) {
    if(this.tarjeta.length === 16) {
    return {
        ...super.makePay(cantidadAPagar),
        lastCardNumbers: this.tarjeta.substring(this.tarjeta.length - 4)
      }
    }else{
      throw new Error(`Deben de ser 16 digitos`)
    }
  }
}
class Cash extends Pay{
  makePay(cantidadAPagar) {
    return {
      ...super.makePay(cantidadAPagar)
    }
  }
}

Mi soluci贸n:

C贸digo Clase Pay

export class Pay {
  constructor() {
    this.realized = true;
    this.quantity = 0;

  }
  makePay(quantity) {
    this.quantity = quantity;
    return this;
  }
}

C贸digo Clase PayPal

import { Pay } from "./Pay.class.js";

export class PayPal extends Pay {
  constructor(emailRecibido) {
    super();
    this.platform = "PayPal";
    this.email = emailRecibido;
  }
  makePay(quantity) {
    this.quantity = quantity;
    return this;
  }
}

C贸digo Clase Card

import { Pay } from "./Pay.class.js";

export class Card extends Pay {
  constructor(cardNumber) {
    super();
    this.lastCardNumbers = cardNumber;
  }
  makePay(quantity) {
    if (this.lastCardNumbers < 16) {
      throw new Error("Se esperaban 16 d铆gitos en el n煤mero de tarjeta");
    }
    this.quantity = quantity;
    this.lastCardNumbers = this.lastCardNumbers.substr(12, 16);
    return this;
  }
}

C贸digo Clase Cash

import { Pay } from "./Pay.class.js";

export class Cash extends Pay {
  // Tu c贸digo aqu铆 馃憟
  constructor() {
    super();
  }
}

y el c贸digo de la clase exercise.js

export function processPay(method, quantity) {
  return method.makePay(quantity);
}

Soluci贸n鈥 馃槃
.
Para resolver el ejercicio, se deben implementar las clases correspondientes.
.
NOTA:

  • En la descripci贸n del ejercicio, en la clase 鈥淐ard鈥 se dice que se debe agregar la atributo 鈥渓astCardNumber鈥 al objeto a retornar en el m茅todo makePay(). Pero es necesario agregar la propiedad 鈥渓astCardNumbers鈥, con 鈥榮鈥 para que las pruebas pasen bien.
    .

Para recortar los 煤ltimos caracteres de un String tambi茅n puede utilizarse el m茅todo:
.

 "slice(<#caracteres>)"
/*
Donde <#caracteres> es un valor negativo que pasamos como primer par谩metro para obtener los 煤ltimos caracteres de un string.
*/

.
Card.class.js
.

import { Pay } from "./Pay.class.js";

export class Card extends Pay {
  constructor(number) {
    super();
    this.number = number;
  }

  makePay(quantity) {
    if (this.number.length != 16) { 
      throw new Error("El n煤mero de d铆gitos no de 16");
    }
    return {
      ...super.makePay(quantity),
      lastCardNumbers: this.number.slice(-4)
    }
  }
} 

.
Cash.class.js
.

import { Pay } from "./Pay.class.js";

export class Cash extends Pay {
  constructor() {
    super();
  }

  makePay(quantity) {
    return { ...super.makePay(quantity) };
  }
}

.
Pay.class.js
.

export class Pay {
  makePay(quantity) { 
    return {
      realized: true,
      quantity: quantity
    }
  }
} 

.
PayPal.class.js
.

import { Pay } from "./Pay.class.js";

export class PayPal extends Pay {
  constructor(email) { 
    super();
    this.email = email;
  }

  makePay(quantity) {
    return {
      ...super.makePay(quantity),
      platform: "PayPal",
      email: this.email
    }
  }
}

.
exercise.js
.

export function processPay(method, quantity) {
  return method.makePay(quantity);
}

Mi soluci贸n

Dentro del archivo exercise.js, la funci贸n retorna el resultado que los diferentes m茅todos de pago devuelvan, ya que todos se llaman con la misma funci贸n makePay() por el Polimorfismo.

Cada m茅todo de pago Card,Cash y PayPal, tienen sus propios constructores donde reciben una propiedad propia, pero heredan la clase Pay.

La clase padre Pay, tiene el m茅todo makePay(), que recibe como par谩metro la cantidad y retorna si la compra fue realizada y la cantidad.

Por 煤ltimo dentro de las funciones makePay() de los diferentes m茅todos de pago, retorno un objeto con el objeto de la clase padre y sus propiedades propias.

Para hacer eso us茅 鈥渟uper鈥 para acceder a la clase padre y llamando a makePay(), lo que devuelva uso el spread operator para que todo termine en un solo objeto.

export function processPay(method, quantity) {
  return method.makePay(quantity);
}
export class Pay {
  constructor() {
    this.quantity = 0;
  }
  makePay(quantity) {
    this.quantity = quantity;
    return {
      realized: true,
      quantity:this.quantity
    }
  }
}
export class PayPal extends Pay {
  constructor(email) {
    super();
    this.email = email;
  }
  makePay(quantity) {
    return {...super.makePay(quantity), platform: 'PayPal', email: this.email };
  }
}
export class Card extends Pay {
  constructor(cardNumber) {
    super();
    this.cardNumber = cardNumber;
  }
  makePay(quantity) {
    if (this.cardNumber.length != 16) {
      throw new Error("Hubo un error al realizar el pago, ingrese nuevamente los 16 digitos");
    }
    return {
      ...super.makePay(quantity),
      lastCardNumbers: this.cardNumber.slice(-4)
    };
  }
}
export class Cash extends Pay {
  constructor() {
    super();
  }
  makePay(quantity) {
    return super.makePay(quantity);
  }
}

Mi aporte ;D
.
.
.
.
.
.
.
.
.
Card

import { Pay } from "./Pay.class.js";

export class Card extends Pay {
  constructor(cardNumber) {
    super();
    this.cardNumber = cardNumber;
  }
  makePay(quantity) {
    if (this.cardNumber.length === 16) {
      return {
        ...super.makePay(quantity),
        lastCardNumbers: this.cardNumber.toString().substr(-4, 4)
      }
    }
    else {
      throw new Error("No son 16")
    }
  }
}
	Cash
import { Pay } from "./Pay.class.js";

export class Cash extends Pay {
  constructor() { 
    super();
  }
}
		Pay
export class Pay {
  constructor() { };
  makePay(quantity) { return { realized: true, quantity: quantity } };
}
	PayPal
import { Pay } from "./Pay.class.js";
export class PayPal extends Pay {
  constructor(email) {
    super();
    this.email = email;
  }
  makePay(quantity) {
    return {
      ...super.makePay(quantity),
      platform: "PayPal",
      email: this.email
    }
  }
}
	Exercise
export function processPay(method, quantity) {
  return method.makePay(quantity);
}

Hay un peque帽o error en el enunciado. El ejercicio habla de la propiedad lastCardNumber, pero en las pruebas se pide la propiedad lastCardNumbers.
Mi soluci贸n:
.
.
.
.
.

Card.class.js

import { Pay } from "./Pay.class.js";

export class Card extends Pay {
  constructor(cardNumber) {
    super()
    this.cardNumber = cardNumber
  }
  makePay(quantity) {
    if (this.cardNumber.length === 16) {
      return {...super.makePay(quantity), lastCardNumbers: this.cardNumber.slice(-4)}
    } else {
      throw new Error("El n煤mero de tarjeta no es v谩lido")
    }
  }
}

Cash.class.js

import { Pay } from "./Pay.class.js";

export class Cash extends Pay {
  makePay(quantity) { return { ...super.makePay(quantity) } }
}

Pay.class.js

export class Pay {
  makePay(quantity) { return {realized: true, quantity: quantity} }
}

PayPal.class.js

import { Pay } from "./Pay.class.js";

export class PayPal extends Pay {
  constructor(email) {
    super()
    this.email = email
  }
  makePay(quantity) {
    return {...super.makePay(quantity), platform: "PayPal", email: this.email}
  }
}

exersice.js

export function processPay(method, quantity) {
  return method.makePay(quantity)
}

SPOILER ALERT
.
.
.
.
.
.
.
.

export class Pay {
  makePay(quantity) {
    return {
      realized: true,
      quantity,
    };
  }
}

export class PayPal extends Pay {
  constructor(email) {
    super();
    this.email = email;
  }

  makePay(quantity) {
    return {
      ...super.makePay(quantity),
      platform: 'PayPal',
      email: this.email,
    };
  }
}

export class Card extends Pay {
  constructor(cardNumber) {
    super();
    this.cardNumber = cardNumber;
  }

  makePay(quantity) {
    if (this.cardNumber.length < 16) {
      throw new Error('La tarjeta debe tener minimo 16 digitos');
    }
    return {
      ...super.makePay(quantity),
      lastCardNumbers: this.cardNumber.slice(-4),
    };
  }
}

export class Cash extends Pay {}

export function processPay(method, quantity) {
  return method.makePay(quantity);
}

.
. -----------------------------------------
. ESCUDO ANTI SPOILER
. -----------------------------------------
.
. Este reto si que me hizo sudar.
.
.

.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.

undefined