Advertisement
Guest User

Untitled

a guest
Jul 21st, 2019
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.47 KB | None | 0 0
  1. class ShoppingCart {
  2. constructor() {
  3. this.cart = [];
  4. }
  5.  
  6. addItem(item) {
  7. this.cart.push(item);
  8. }
  9.  
  10. removeItem(item) {
  11. this.cart.splice(this.cart.indexOf(item), 1);
  12. }
  13.  
  14. listItems() {
  15. return this.cart.join(", ");
  16. }
  17. }
  18.  
  19. const bigBasket = new ShoppingCart();
  20.  
  21. bigBasket.addItem('rice');
  22. bigBasket.addItem('dal');
  23. bigBasket.addItem('tomato');
  24.  
  25. bigBasket.listItems(); // rice, dal, tomato
  26.  
  27. bigBasket.removeItem('tomato');
  28.  
  29. bigBasket.listItems(); // rice, dal
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement