Skip to content

Instantly share code, notes, and snippets.

@jasongorman
Created July 26, 2019 08:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jasongorman/0c18879d42dff1c84b3c9c3b65afd5b7 to your computer and use it in GitHub Desktop.
Save jasongorman/0c18879d42dff1c84b3c9c3b65afd5b7 to your computer and use it in GitHub Desktop.
class CD {
constructor(price, stock, description) {
this.price = price;
this.stock = stock;
this.description = description;
}
buy(payments, creditCard) {
if(this.stock == 0){
throw new OutOfStockError();
}
let paymentAccepted = payments.process(this.price, creditCard);
if(paymentAccepted){
this.stock--;
}
}
matches(title, artist) {
return this.description.matches(title, artist);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment