Created
July 26, 2019 08:39
-
-
Save jasongorman/0c18879d42dff1c84b3c9c3b65afd5b7 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, 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