Переглянути джерело

Finish objects-method restaurant model

Signed-off-by: Michael Tang <michael.h.tang@gmail.com>
Michael Tang 5 роки тому
батько
коміт
c716b35588
1 змінених файлів з 28 додано та 0 видалено
  1. 28 0
      objects-methods.js

+ 28 - 0
objects-methods.js

@@ -0,0 +1,28 @@
+let restaurant = {
+    name: 'Red Lobster',
+    guestCapacity: 75,
+    guestCount: 0,
+    checkAvailability: function (partySize) {
+        let seatsLeft = this.guestCapacity - this.guestCount
+
+        return partySize <= seatsLeft
+    },
+    seatParty: function (guests) {
+        this.guestCount = this.guestCount + guests
+        console.log(`seating ${guests}, total is now ${this.guestCount}/${this.guestCapacity}.`)
+    },
+    removeParty: function(guests) {
+        this.guestCount = this.guestCount - guests
+        console.log(`${guests} leaving, total is now ${this.guestCount}/${this.guestCapacity}.`)
+    }
+}
+
+// seatParty
+
+// removeParty
+
+restaurant.seatParty(72)
+console.log(restaurant.checkAvailability(4))
+restaurant.removeParty(5)
+console.log(restaurant.checkAvailability(4))
+