Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class ShoppingCart {
- constructor() {
- this.cart = [];
- }
- addItem(item) {
- this.cart.push(item);
- }
- removeItem(item) {
- this.cart.splice(this.cart.indexOf(item), 1);
- }
- listItems() {
- return this.cart.join(", ");
- }
- }
- const bigBasket = new ShoppingCart();
- bigBasket.addItem('rice');
- bigBasket.addItem('dal');
- bigBasket.addItem('tomato');
- bigBasket.listItems(); // rice, dal, tomato
- bigBasket.removeItem('tomato');
- bigBasket.listItems(); // rice, dal
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement