Skip to content

Instantly share code, notes, and snippets.

@jasongorman
Created July 26, 2019 08:11
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/301a9a9c7957a2448cfa2a1e505e49ff to your computer and use it in GitHub Desktop.
Save jasongorman/301a9a9c7957a2448cfa2a1e505e49ff to your computer and use it in GitHub Desktop.
class CD {
constructor(price, stock, title, artist) {
this.price = price;
this.stock = stock;
this.title = title;
this.artist = artist;
}
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.title == title && this.artist == artist;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment