Book

Run Settings
LanguageJavaScript
Language Version
Run Command
class Book{ constructor(title, author, isbn, numCopies){ this.title=title; this.author=author; this.isbn=isbn; this.numCopies=numCopies; } get availability(){ return this.getAvailability(); } getAvailability= ()=>{ if (this.numCopies===0){ return "out of stock"; } if(this.numCopies<10){ return "low stock"; } return "in stock"; } sell= (numSold=1)=>{ if(numSold<this.numCopies||numSold===this.numCopies){ this.numCopies-=numSold; } else{ if(this.numCopies>0){ this.numCopies-=1; } } } restock= (numCopies=5)=>{ this.numCopies+=numCopies; return this; } } const HungerGames = new Book("Hunger Games","Suzanne Collins", 123919, 5); console.log(HungerGames.availability); HungerGames.restock(120); console.log(HungerGames.availability); HungerGames.sell(17); console.log(HungerGames.availability);
Editor Settings
Theme
Key bindings
Full width
Lines