Created
July 26, 2019 08:11
-
-
Save jasongorman/301a9a9c7957a2448cfa2a1e505e49ff to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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