objects-methods.js 794 B

12345678910111213141516171819202122232425262728
  1. let restaurant = {
  2. name: 'Red Lobster',
  3. guestCapacity: 75,
  4. guestCount: 0,
  5. checkAvailability: function (partySize) {
  6. let seatsLeft = this.guestCapacity - this.guestCount
  7. return partySize <= seatsLeft
  8. },
  9. seatParty: function (guests) {
  10. this.guestCount = this.guestCount + guests
  11. console.log(`seating ${guests}, total is now ${this.guestCount}/${this.guestCapacity}.`)
  12. },
  13. removeParty: function(guests) {
  14. this.guestCount = this.guestCount - guests
  15. console.log(`${guests} leaving, total is now ${this.guestCount}/${this.guestCapacity}.`)
  16. }
  17. }
  18. // seatParty
  19. // removeParty
  20. restaurant.seatParty(72)
  21. console.log(restaurant.checkAvailability(4))
  22. restaurant.removeParty(5)
  23. console.log(restaurant.checkAvailability(4))